NotificationListenerService works intermittently for Oreo

試著忘記壹切 提交于 2019-12-24 10:46:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!