gpt4 book ai didi

java - NotificationListenerService : NullPointerException on getActiveNotifications

转载 作者:搜寻专家 更新时间:2023-10-30 21:44:32 25 4
gpt4 key购买 nike

我正在尝试根据本教程在我的应用程序中实现 NotificationListenerService:http://www.kpbird.com/2013/07/android-notificationlistenerservice.html ,但我在调用 getActiveNotifications 时遇到 NullPointerException。

Caused by: java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1437)
at android.os.Parcel.readException(Parcel.java:1385)


at android.app.INotificationManager$Stub$Proxy.getActiveNotificationsFromListener(INotificationManager.java:500)
at android.service.notification.NotificationListenerService.getActiveNotifications(NotificationListenerService.java:149)
at com.rootsoft.rsnotificationservice.RSNotificationService.activeNot(RSNotificationService.java:85)
at com.rootsoft.rsnotificationservice.RSNotificationService.access$0(RSNotificationService.java:81)
at com.rootsoft.rsnotificationservice.RSNotificationService$1.onReceive(RSNotificationService.java:105)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:763)
... 9 more

我正在向应该生成所有通知列表的服务发送广播:

private void activeNot () {
List l = new List();
l.Initialize();

for (StatusBarNotification sbn : getActiveNotifications() ) { <---- Error happens here
l.Add(sbn);
}

Log.i("B4A", "List created.");


}
}

最佳答案

编辑:从那以后我了解了更多这方面的知识并让它开始工作!

注意:首先,确保您已在 Android 设备的通知访问设置面板中启用您的应用。

到目前为止,我遇到了完全相同的问题。事实证明,覆盖 onBind 是危险的。如果您确实覆盖了 onBind,则必须返回与 super.onBind(intent) 返回的相同的 IBinder。如果您想返回自己的自定义 Binder ,请确保使用唯一的 Intent ,并且仅在收到自定义 Intent 时才返回自定义 Binder 。

@Override
public IBinder onBind(Intent intent)
{
if (intent.getAction().equals("custom_intent"))
{
return customBinder;
}
else
{
return super.onBind(intent);
}
}

一旦您授予它读取通知的权限,系统就会在您的服务上调用 onBind。如果您的 onBind 向系统返回自定义绑定(bind)器,系统将不会给您通知,并可能导致空指针或安全异常。

希望这对您有所帮助!

关于java - NotificationListenerService : NullPointerException on getActiveNotifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18684738/

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