Skip to content

Commit

Permalink
#Fixed#
Browse files Browse the repository at this point in the history
NullPointerException in LocalNotificationListenerService: #73
  • Loading branch information
hui.zhao committed May 25, 2020
1 parent 363198d commit bcf239e
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.IBinder;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import java.util.LinkedList;

Expand All @@ -14,6 +15,8 @@
import cn.hikyson.godeye.core.utils.L;

public class LocalNotificationListenerService extends Service {
private static final String ACTION_START = "START_FOREGROUND_ACTION";
private static final String ACTION_STOP = "STOP_FOREGROUND_ACTION";
private int mNotificationId;
private LinkedList<String> mLatestMessages;
private int mCount;
Expand All @@ -22,15 +25,13 @@ public static void start(String message, boolean isStartup) {
Intent intent = new Intent(GodEye.instance().getApplication(), LocalNotificationListenerService.class);
intent.putExtra("message", message);
intent.putExtra("isStartup", isStartup);
intent.setAction("START_FOREGROUND_ACTION");
// TODO KYSON DEL
// ContextCompat.startForegroundService(GodEye.instance().getApplication(), intent);
GodEye.instance().getApplication().startService(intent);
intent.setAction(ACTION_START);
ContextCompat.startForegroundService(GodEye.instance().getApplication(), intent);
}

public static void stop() {
Intent intent = new Intent(GodEye.instance().getApplication(), LocalNotificationListenerService.class);
intent.setAction("STOP_FOREGROUND_ACTION");
intent.setAction(ACTION_STOP);
GodEye.instance().getApplication().startService(intent);
}

Expand All @@ -44,10 +45,13 @@ public void onCreate() {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ("START_FOREGROUND_ACTION".equals(intent.getAction())) {
// TODO KYSON DEL
// startForeground(mNotificationId, updateNotification(intent));
} else if ("STOP_FOREGROUND_ACTION".equals(intent.getAction())) {
if (intent == null) {
L.w("LocalNotificationListenerService onStartCommand intent == null");
return START_REDELIVER_INTENT;
}
if (ACTION_START.equals(intent.getAction())) {
startForeground(mNotificationId, updateNotification(intent));
} else if (ACTION_STOP.equals(intent.getAction())) {
stopForeground(true);
stopSelf();
}
Expand Down Expand Up @@ -80,12 +84,6 @@ private Notification updateNotification(Intent intent) {
return Notifier.create(this, new Notifier.Config(title, sb.toString()));
}

@Override
public void onDestroy() {
super.onDestroy();
L.d("LocalNotificationListenerService onDestroy");
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
Expand Down

0 comments on commit bcf239e

Please sign in to comment.