问题描述
我上课
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");
}
}
我在处设置了一个断点
String notificationTitle = getActiveNotifications()[i].getNotification().extras.getString("android.title");
内部onNotificationPosted(StatusBarNotification sbn)方法.
inside onNotificationPosted(StatusBarNotification sbn) method.
这是一个回调方法,当设备收到任何通知时将调用该方法.在Android Nougat上运行时,它工作得非常好.但是它在Android Oreo中间歇性地命中.有时会命中,有时却不会.
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.
我不确定真正的问题及其解决方案,但是当我遇到服务问题时,可以使用JobScheduler阅读activeNotifications吗?我正在使用API 26
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
推荐答案
我已经为这个问题研究了很长时间了.当我通过Google Nexus/像素设备或模拟器运行该服务时,该服务会间歇性地工作.我尝试在Honor上运行它,而Samsung S9和NotificationListenerService
在此方面运行良好.因此,我得出结论,问题出在Google设备上,而不是服务上.
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.
请注意,如果设备在低RAM上运行,则NotificationListenerService
很有可能会停止工作.
Just a note that if the device is running on low-RAM, there are great chances that NotificationListenerService
will stop working.
这篇关于NotificationListenerService为Oreo间歇性工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!