我有一个简单的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); } }
糟糕的是堆栈跟踪是没用的.出了什么问题?