forked from jens/Automation
Notification listener started.
This commit is contained in:
@ -1,48 +1,55 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
// See here for reference: http://gmariotti.blogspot.com/2013/11/notificationlistenerservice-and-kitkat.html
|
||||
|
||||
@SuppressLint("OverrideAbstract")
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public class NotificationListener extends NotificationListenerService
|
||||
{
|
||||
static NotificationListener instance;
|
||||
// the title of the notification,
|
||||
public static final String EXTRA_TITLE = "android.title";
|
||||
|
||||
// the main text payload
|
||||
public static final String EXTRA_TEXT = "android.text";
|
||||
|
||||
public static boolean startNotificationListenerService()
|
||||
{
|
||||
if(instance == null)
|
||||
instance = new NotificationListener();
|
||||
// a third line of text, as supplied to
|
||||
public static final String EXTRA_SUB_TEXT = "android.subText";
|
||||
|
||||
instance.c
|
||||
}
|
||||
// a bitmap to be used instead of the small icon when showing the notification payload
|
||||
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
nlservicereciver = new NLServiceReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("com.kpbird.nlsexample.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
|
||||
registerReceiver(nlservicereciver,filter);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn)
|
||||
{
|
||||
super.onNotificationPosted(sbn);
|
||||
String app = sbn.getPackageName();
|
||||
String title = sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
String text = sbn.getNotification().extras.getString(EXTRA_TEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap)
|
||||
{
|
||||
super.onNotificationPosted(sbn, rankingMap);
|
||||
}
|
||||
// @Override
|
||||
// public void onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap)
|
||||
// {
|
||||
// super.onNotificationPosted(sbn, rankingMap);
|
||||
// sbn.getNotification().extras.getString(EXTRA_TITLE);
|
||||
// sbn.getNotification().extras.getString(EXTRA_TEXT;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onListenerConnected()
|
||||
@ -56,5 +63,9 @@ public class NotificationListener extends NotificationListenerService
|
||||
super.onListenerDisconnected();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static void openNotificationAccessWindow(Context context)
|
||||
{
|
||||
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user