简体   繁体   English

通知侦听器服务并不总是有效

[英]Notification Listener Service not always working

I'm trying to work on an app that sends notifications to my pc.我正在尝试开发一个向我的电脑发送通知的应用程序。 I used an NotificationListenerService which seems to work on an Emulator(Pixel XL API29) but when trying it on my Oneplus 7 Pro (Android 10) it only works randomly.我使用了一个NotificationListenerService ,它似乎可以在模拟器(Pixel XL API29)上运行,但是在我的 Oneplus 7 Pro(Android 10)上尝试时,它只能随机运行。

My Code can be found here as I want to make it open source or at least visible for others: https://github.com/MrMinemeet/PhoneConnect我的代码可以在这里找到,因为我想让它开源或至少对其他人可见: https : //github.com/MrMinemeet/PhoneConnect

onCreate in the NotificationReceiver.class get's called as a breakpoint will stop there. NotificationReceiver.classonCreate被调用作为断点将在那里停止。

onNotificationPostet on the other hand is randomly working and then from one minute to the other stops getting called when a new notification arrives.另一方面, onNotificationPostet随机工作,然后从一分钟到另一分钟在新通知到达时停止调用。 There aren't any errors it just won't get called.没有任何错误,只是不会被调用。

I tried it on the Huawei phone (Android 7 or 8) of my friend where it has the same behavior.我在我朋友的华为手机(Android 7 或 8)上尝试过,它具有相同的行为。

In my opinion it's very strange as I always grant the permissions.在我看来,这很奇怪,因为我总是授予权限。

I used this example project as a guideline to build my own app on: https://github.com/Chagall/notification-listener-service-example我使用这个示例项目作为指南来构建我自己的应用程序: https : //github.com/Chagall/notification-listener-service-example

Hopefully someone finds out what I'm missing.希望有人发现我错过了什么。

Try to implement the code above尝试实现上面的代码

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    return START_NOT_STICKY;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM