Reputation: 5904
i'm using NotificationListenerService
to retrive the informations from notifications. Actually i can display in a textview only the last notification that i see in the notifications bar. I want, if possible, filter this method and display only the whatsapp notifications. I can get the package name and display it in the LOG but i don't know i do the filter. This is a part of NotificaionListenerService
public void onNotificationPosted(StatusBarNotification sbn) {
Notification mNotification=sbn.getNotification();
if (mNotification!=null){
Bundle extras = mNotification.extras;
Intent intent = new Intent(MainActivity.INTENT_ACTION_NOTIFICATION);
intent.putExtras(mNotification.extras);
sendBroadcast(intent);
TAG = "onNotificationPosted";
Log.i(TAG,"Package Name" + sbn.getPackageName());
Notification.Action[] mActions=mNotification.actions;
if (mActions!=null){
for (Notification.Action mAction:mActions){
int icon=mAction.icon;
CharSequence actionTitle=mAction.title;
PendingIntent pendingIntent=mAction.actionIntent;
}
}
}
}
in which i can see the package name of the apps that creates the notifications. Is it there that i have to make the filter? How can i do it? Thanks
Upvotes: 0
Views: 597
Reputation: 3450
As simple as doing this:
if("com.the.package.name.you.want.to.filter".equals(sbn.getPackageName())) {
//Do something
}
or if there is more than one, you can have them in a hashmap or list, and see if the package is in there or not.
Upvotes: 1