本文介绍了NotificationListenerService不起作用-即使在授予权限后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的捕获通知的代码.我不明白为什么 onNotificationPosted 没有被解雇.
Below is my code to capture notifications. I dont understand why the onNotificationPosted is not getting fired.
我正在通过设置">安全性"为我的应用程序授予通知"访问权限,同时还触发了MyNotifService的 onCreate ,但没有触发 onNotificationPosted .
I am giving my app Notifications access from Settings > Security and the onCreate from MyNotifService is also getting fired, but onNotificationPosted is not getting fired.
我想念什么或做错什么了?
What am I missing or doing wrong?
通过我的 MainActivity的onCreate()函数:
Intent intent = new Intent(this, MyNotifService.class);
this.startService(intent);
扩展 NotificationListenerService 的我的服务代码:
@SuppressLint("NewApi")
public class MyNotifService extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
Log.v("focus", "in onNotificationPosted() of MyNotifService");
}
@Override
public void onCreate() {
super.onCreate();
Log.v("focus", "in onCreate() of MyNotifService");
}
}
在清单文件中,我有这个:
<service android:name="com.mavdev.focusoutfacebook.notifications.MyNotifService"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
推荐答案
这似乎有些胡扯,但这是此例中的实际解决方法:
It does seem to be a bit flakey, but this is the actual fix in this case:
@Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}
这篇关于NotificationListenerService不起作用-即使在授予权限后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!