我正在尝试开发一个向我的电脑发送通知的应用程序。
我使用了 NotificationListenerService
,它似乎可以在模拟器(Pixel XL API29)上运行,但在我的 Oneplus 7 Pro (Android 10) 上尝试它时,它只能随机运行。
我的代码可以在这里找到,因为我想将其开源或至少对其他人可见:https://github.com/MrMinemeet/PhoneConnect
onCreate
在 NotificationReceiver.class
get 中调用作为断点将在那里停止。
onNotificationPostet
是随机工作的,然后当新通知到达时,从一分钟到另一分钟停止被调用。
没有任何错误,只是不会被调用。
我在我 friend 的华为手机(Android 7或8)上尝试过,它有相同的行为。
在我看来,这很奇怪,因为我总是授予权限。
我使用此示例项目作为构建我自己的应用程序的指南: https://github.com/Chagall/notification-listener-service-example
希望有人能发现我错过了什么。
最佳答案
尝试实现上面的代码
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_NOT_STICKY;
}
关于java - 通知监听器服务并不总是工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59437538/