gpt4 book ai didi

android - NotificationListenerService 不工作 - 即使在给予许可后

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:11 29 4
gpt4 key购买 nike

下面是我捕获通知的代码。我不明白为什么 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com