问题
I have a class
public class NotifClass extends NotificationListenerService{
@Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}
@Override
public void onNotificationPosted(StatusBarNotification sbn){
String notifiTitle = getActiveNotifications()[i].getNotification().extras.getString("android.title");
}
}
I've put a breakpoint at
String notificationTitle = getActiveNotifications()[i].getNotification().extras.getString("android.title");
inside onNotificationPosted(StatusBarNotification sbn) method.
This is a callback method which is called when device receives any notification. It works perfectly fine while running over Android Nougat. But it hits intermittently in Android Oreo. Sometimes it hits and sometimes doesn't.
I'm not sure about the real issue and its solution but can I read activeNotifications using JobScheduler as I'm facing issue with Service? I'm running over API 26
回答1:
I've been working over this issue for quite a long. When I'm running it over Google Nexus/pixel device or emulator, this service works intermittently.
I tried running it over Honor and Samsung S9 and NotificationListenerService
works perfectly fine in that.
So I concluded that the issue is with Google devices and not the service.
Just a note that if the device is running on low-RAM, there are great chances that NotificationListenerService
will stop working.
来源:https://stackoverflow.com/questions/51629526/notificationlistenerservice-works-intermittently-for-oreo