class NLServiceReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra("command").equals("clearall")) {
NLService.this.cancelAllNotifications();
} else if (intent.getStringExtra("command").equals("list")) {
Intent notificationIntent = new Intent("com.example.superapp.NOTIFICATION_LISTENER_EXAMPLE");
notificationIntent.putExtra("notification_event", "=======");
sendBroadcast(notificationIntent);
int i = 1;
for (StatusBarNotification sbn : NLService.this.getActiveNotifications()) {
Intent infoIntent = new Intent("com.example.superapp.NOTIFICATION_LISTENER_EXAMPLE");
infoIntent.putExtra("notification_event", i + " " + sbn.getPackageName() + "\\n");
sendBroadcast(infoIntent);
i++;
}
Intent listIntent = new Intent("com.example.superapp.NOTIFICATION_LISTENER_EXAMPLE");
listIntent.putExtra("notification_event", "Notification List");
sendBroadcast(listIntent);
}
}
}