Android /使用NotificationListenerService类的onResume()函数覆盖

时间:2018-12-07 12:43:49

标签: android notifications android-notifications onresume notification-listener

在Android中,我必须阅读移动应用程序中所有尚未清除的现有状态栏通知,但其中还包括以前发布的通知,不一定每次活动时都会收到新通知我自己的Android应用程序已永久恢复。

当然,通过在getActiveNotifications()类的覆盖的onCreate()函数中使用NotificationListenerService函数,如下所示:

@Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();

        StatusBarNotification notifications[] = getActiveNotifications();
        for(StatusBarNotification item : notifications) {
            if(item != null) {
                Bundle extras = item.getNotification().extras;
                String title = extras.getString("android.title");
                Log.i("Title", title);
            }
        }
    }

只有在创建NotificationListenerService类时,它们才第一次被读取,而当我切换到另一个移动应用程序并返回到该移动应用程序时,或者当该移动应用程序被恢复时,它们才第一次被读取。以前已经在我的移动设备上打开过此移动应用程序时,将连续启动该应用程序。

当然,看来onResume()类中没有NotificationListenerService函数可以覆盖。任何人都可以帮我解决这个问题的方法,即如何从我的移动应用中读取所有现有的状态栏通知,这些通知尚未撤消,但还包括以前发布的通知,不一定永久恢复我自己的Android应用程序每次活动期间收到的新通知吗?

0 个答案:

没有答案