Try to search your question here, if you can't find : Ask Any Question Now ?

get list of active notifications in androidStudio

HomeCategory: stackoverflowget list of active notifications in androidStudio
pushpa asked 2 weeks ago

Hello I’m trying to get a list of all active notifications in java android studio and I’m having trouble figuring out how to do so with the information given in the documentation.

My plan is to start with creating a StatusBarNotification object and then calling getActiveNotifications(), but I’m having trouble with the first part of declaring the StatusBarNotification object In my file “NotificationMonitor.java” the getCurrentNotifications() function gets called when a button is pressed:

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();
}

}

StatusBarNotification is described as a class I believe from what I’ve read online:

https://developer.android.com/reference/android/service/notification/StatusBarNotification

which makes me think I can just create a new instance of said class as an object? I’ve been looking at many notification listener example projects online but they never directly declare StatusBarNotification which has me confused.

Thanks, -Martin

1 Answers
Best Answer
Jyoti answered 2 weeks ago
Your Answer

6 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com