Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,
was learning notifications in Android and was wonderring why was this code not working... instead its returning Null?

This code snippet is from my MainActivity ,
NotificationService is my public class that extends NotificationListenerService
i have also made the necessary permissions in the Manifest for my app to watch notifications!


Java
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

NotificationService ns = new NotificationService();
StatusBarNotification[] sbn = ns.getActiveNotifications();
      
        if (sbn != null)
        	{
        	Log.i("XXXXXX", "Lenght: " + sbn.length);
        	}
        else
        	{
        	Log.i("XXXXXX", "Null" );
        	}
       
    }


I am trying to get the getActiveNotifications() inside the NotificationListenerService to return me an array of the Notifications that are already present in the statusbar before i had launched my app... so after i have launched the app and the OnCreate is fired... i still get Null even though there are 4 current notifications?
Posted

 
Share this answer
 
Comments
Lg Opt 2-Dec-15 8:33am    
This is nothing!
i have been through each and every one of this prior to my question..
Not one of them solve getting a notification that already exists( or is presently in the statusbar)!
Any other ideas???
Richard Deeming 2-Dec-15 14:57pm    
So why not include that information in the question, rather than letting other people waste their time posting solutions that you've already tried?
Lg Opt 2-Dec-15 17:44pm    
I did .. the solution to all those problems in the search... was the permission was missing in their manifest file...
Please read my line again...
" have also made the necessary permissions in the Manifest for my app to watch notifications!"
Please make sure you have enabled your app in the Notification Access settings pane of your Android device.

Enable your application in Notification Access section from Settings -> Security
 
Share this answer
 
Comments
Lg Opt 2-Dec-15 17:46pm    
hi man...
hahaaa... thanx.. but that was the first thing i double checked when i was doing Rnd too!... see that line i wrote above..
" have also made the necessary permissions in the Manifest for my app to watch notifications!"
... have any other ideas... its just wierd ... beats me??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900