加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – NotificationListenerService:getActiveNotifications

发布时间:2020-12-14 05:08:08 所属栏目:Java 来源:网络整理
导读:根据本教程,我试图在我的应用程序中实现NotificationListenerService: http://www.kpbird.com/2013/07/android-notificationlistenerservice.html,但是当调用getActiveNotifications时,我有一个NullPointerException. Caused by: java.lang.NullPointerExce
根据本教程,我试图在我的应用程序中实现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,则必须返回super.onBind(intent)返回的相同IBinder.如果要返回自己的自定义绑定器,请确保使用唯一的意图,并且仅在收到自定义意图时返回自定义绑定.

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

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

希望这有帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读