0
我有一個應用程序,它讀取設備中的所有通知,然後將該通知存儲在Activity
包含ListView
之後,然後從狀態欄中刪除該通知。爲此,我使用了「NotificationListenerService
」。如何閱讀和打開Android中的所有通知?
當我點擊包含通知的ListView
時,我想在其目標應用程序中打開該通知。我怎麼做?
碼我用:
public void onNotificationPosted(StatusBarNotification sbn) {
Log.i("Msg", "Notification Posted");
String pack = sbn.getPackageName();
String ticker = "";
if (sbn.getNotification().tickerText != null) {
ticker = sbn.getNotification().tickerText.toString();
}
Bundle extras = sbn.getNotification().extras;
String title = extras.getString("android.title");
String text = null;
if (extras.getCharSequence("android.text") != null) {
text = extras.getCharSequence("android.text").toString();
}
Bitmap id = sbn.getNotification().largeIcon;
;
if (id != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
id.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
}
String jsonData = sharedPreference.getAppsArrayListData();
Type type = new TypeToken<ArrayList<WhiteListModel>>() {
}.getType();
whiteListModels = gson.fromJson(jsonData, type);
if (whiteListModels != null && whiteListModels.size() > 0)
//loop to insert notification data into db.
{
for (int i = 0; i < whiteListModels.size(); i++) {
model = whiteListModels.get(i);
if (pack.equals(model.getPackName())) {
dbHelper.insertNotification(title, pack, text, byteArray);
}
}
//loop to remove notification from status bar.
for (int i = 0; i < whiteListModels.size(); i++) {
model = whiteListModels.get(i);
if (pack.equals(model.getPackName())) {
NotificationService.this.cancelNotification(sbn.getKey());
}
}
}
}
我想在目標應用 – Raghav
打開通知頁面,我不認爲這是可能 – Anil
你怎麼發現至極活動,片段或其他任何他們正在用於顯示通知。 – Anil