Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NotificationListenerService throws DeadObjectException

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?

like image 960
tolgap Avatar asked Sep 14 '13 13:09

tolgap


People also ask

What is DeadObjectException Android?

DeadObjectException - The object you are calling has died because its hosting process no longer exists.

How do I use NotificationListenerService?

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.

What is a notification listener service?

A service that receives calls from the system when new notifications are posted or removed, or their ranking changed.

How do I turn on notification listener in access?

For those running versions of Android higher than 5.0, please enable our Notification listener under Settings > Sound and notifications > Notification access.


1 Answers

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.

like image 78
Gabe Avatar answered Sep 27 '22 18:09

Gabe