Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android NotificationListenerService抛出DeadObjectException大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个简单的NotificationListenerservice实现来测试新的4.3 API.服务本身曾经工作过.之后,我添加了在添加特定包的通知时发送广播.现在,只要我启动该服务,它就会抛出一个DeadObjectException.这是堆栈跟踪:
E/Notificationservice﹕ unable to notify listener (posted): android.service.notification.INotificationListener$stub$Proxy@42c047a0
    android.os.DeadObjectException
    at android.os.binderProxy.transact(Native Method)
    at android.service.notification.INotificationListener$stub$Proxy.onNotificationPosted(INotificationListener.java:102)
    at com.android.server.notificationmanagerservice$NotificationListenerInfo.notifyPostedIfUserMatch(notificationmanagerservice.java:241)
    at com.android.server.notificationmanagerservice$2.run(notificationmanagerservice.java:814)
    at android.os.Handler.handleCallBACk(Handler.java:730)
    at android.os.Handler.dispatchmessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at com.android.server.ServerThread.run(SystemServer.java:1000)

这就是我启动服务的方式

@Override
public Boolean onOptionsItemSELEcted(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_start_service:
            startservice(new Intent(this,Connectservice.class));
            return true;
        default:
            return super.onOptionsItemSELEcted(item);
    }
}

我可以验证服务是否启动,因为我登录了onCreate()和onDestroy().
以下是如何处理通知发布的方式:

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Log.i(tag,sbn.getNotification().toString());
    if (sbn != null && sbn.getPackagename().equalsIgnoreCase(PKG)) {
        Intent intent = new Intent(Connectservice.NOTIFY);
        intent.putExtra("notification",sbn.getNotification().toString());
        bManager.sendBroadcast(intent);
    }
}

糟糕的是堆栈跟踪是没用的.出了什么问题?

解决方法

尽量不要自己启动服务.如果已在安全设置中启用NotificationListenerservice,则系统应自动绑定到它.

或者,检查崩溃日志以查看服务是否崩溃或其进程是否已被终止.我相信有一个错误,如果您的NotificaitonListerservice死亡,系统将不会重新绑定,直到您重新启动手机或在安全设置中切换通知权限.

大佬总结

以上是大佬教程为你收集整理的Android NotificationListenerService抛出DeadObjectException全部内容,希望文章能够帮你解决Android NotificationListenerService抛出DeadObjectException所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:android抛出