Java – notificationlistenerservice: NullPointerException on getactivenotifications

According to this tutorial, I try to implement notificationlistenerservice in my application: http://www.kpbird.com/2013/07/android-notificationlistenerservice.html But when getactivenotifications is called, I have a 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

I am sending a broadcast to the service and should generate a list of all notifications:

private void activeNot () {
    List l = new List();
    l.Initialize();

    for (StatusBarNotification sbn : getActiveNotifications() ) { <---- Error happens here
        l.Add(sbn);
    }

    Log.i("B4A","List created.");


    }
}

Solution

Editor: I've learned more about this and got it working!

Note: first, make sure you have enabled your app in the notification access settings pane of your Android device

So far, I have exactly the same problem Facts have proved that it is dangerous to be superior to each other If you override onbind, you must return super The same ibinder returned by onbind (intent) If you want to return your own custom binder, make sure to use a unique intent and return the custom binding only when you receive the custom intent

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

Once you grant permission to read notifications, the system will call onbind. On your service If your onbind returns a custom binding to the system, the system will not notify you, and may cause null pointers or security exceptions

I hope it helps!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>