您好,我正在尝试获取Java android studio中所有活动通知的列表,但无法通过文档中提供的信息来弄清楚该如何做。
我的计划是从创建一个StatusBarNotification
对象开始,然后调用getActiveNotifications()
,但是我在文件{{ 1}} StatusBarNotification
函数在按下按钮时被调用:
NotificationMonitor.java
根据我在网上阅读的内容, getCurrentNotifications()
被描述为一门课程:
https://developer.android.com/reference/android/service/notification/StatusBarNotification
哪个让我认为我可以将所述类的新实例创建为对象?我一直在网上查看许多通知侦听器示例项目,但它们从未直接声明package com.example.notificationstest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
class NotificationMonitor extends NotificationListenerService{
private String TAG = this.getClass().getSimpleName();
Context context;
@Override
public void onCreate() {
super.onCreate();
Log.d("myTag", "onCreate()");
}
@Override
public void onNotificationPosted(StatusBarNotification sbn){
Log.d("myTag", "onNotificationPosted()");
}
public void getCurrentNotifications(){
Log.d("myTag", "getCurrentNotifications()");
//create statusBarNotification object
StatusBarNotification sbn = new StatusBarNotification();
//get list of active notifications
//ActiveNotifications[] = sbn.getActiveNotifications();
}
}
,这使我感到困惑。
谢谢-马丁