我正在尝试将通知发送到我的电脑的应用程序上工作。我使用了NotificationListenerService
,它似乎可以在模拟器(Pixel XL API29)上运行,但是在Oneplus 7 Pro(Android 10)上尝试使用时,它只能随机运行。
我的代码可以在这里找到,因为我想使其开源或至少对其他人可见:https://github.com/MrMinemeet/PhoneConnect
[[onCreate
在NotificationReceiver.class
get中被称为断点将在此处停止。
onNotificationPostet
随机工作,然后从一分钟到另一分钟,当新通知到达时,其他呼叫将停止。没有任何错误,只是不会被调用。
我在行为相同的朋友的华为手机(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;
}