下面是我捕获通知的代码。我不明白为什么 onNotificationPosted 没有被解雇。
我正在通过“设置”>“安全”授予我的应用通知访问权限,MyNotifService 中的 onCreate 也被触发,但 onNotificationPosted 没有被触发。
我错过了什么或做错了什么?
来 self 的 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");
}
}
在 list 文件中,我有这个:
<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>
最佳答案
它看起来确实有点古怪,但这是在这种情况下的实际修复:
@Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}
关于android - NotificationListenerService 不工作 - 即使在给予许可后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27457575/