问题描述
大家好,
在Android中学习通知,并且想知道为什么这段代码无效......而不是它的返回Null?
这段代码片段来自我的MainActivity,
NotificationService是我的公共类,它扩展了NotificationListenerService
i还在Manifest中为我的应用程序发出了必要的权限来观看通知!
受保护 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, 长度: + sbn.length);
}
else
{
Log.i( XXXXXX, Null );
}
}
我想把NotificationListenerService里面的getActiveNotifications()转到在我启动我的应用程序之前,返回状态栏中已经存在的通知数组...所以在我启动应用程序并且OnCreate被解雇后...即使有4个当前通知我仍然会得到Null?
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!
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?
这篇关于为什么getActiveNotifications()返回Null?怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!