I have a simple NotificationListenerService
implementation to test the new 4.3 API. The Service itself used to work. After that, I added the sending of a broadcast when a notification of a particular package is added. Now, as soon as I start the service, it throws a DeadObjectException
. This is the stack trace:
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)
This is how I start the Service
@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);
}
}
I can verify that the Service starts, because I do a Log on it's onCreate()
and onDestroy()
.
And here is how the posting of notifications is handled, if it's needed:
@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);
}
}
The thing that sucks is that the stack trace is of no use. What's going wrong?
DeadObjectException - The object you are calling has died because its hosting process no longer exists.
To use NotificationListenerService, we need to create a java file which extends NotificationListenerService and implement two callback methods. Both methods have a parameter named “sbn”, which is an object of StatusBarNotification class. StatusBarNotification provides necessary information about Notifications.
A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.
For those running versions of Android higher than 5.0, please enable our Notification listener under Settings > Sound and notifications > Notification access.
Try not starting the service yourself. If you have enabled the NotificationListenerService
in the security settings, the system should bind to it automatically.
Alternatively, check your crash logs to see if your service crashed or its process was killed. I believe there is a bug where if your NotificaitonListerService dies, the system will not rebind until you restart your phone or toggle the notifications permission in security settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With