通过我的Android应用程序,我想清除/删除传入消息的消息通知(在Android设备中默认生成),如果它包含关键字。任何人都可以帮忙,我该怎么办?
答案 0 :(得分:1)
使用 NotificationListenerService api 并获取通知ID和文字,然后按通知ID清除通知。
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
String pack = "";
String ticker = "";
String title = "";
String text = "";
String postTime = "";
if (sbn.getPackageName() != null)
pack = sbn.getPackageName();
postTime = sbn.getPostTime() + "";
Bundle extras = sbn.getNotification().extras;
CharSequence data = extras.getCharSequence(Notification.EXTRA_TITLE);
extras.getCharSequence(Notification.EXTRA_TITLE);
if (data != null) {// notification title
title = data.toString();
}
data = extras.getCharSequence(Notification.EXTRA_TEXT);
if (data != null) {// notification text
text = data.toString();
}
String id= sbn.getKey() ;// notification id
}