I have an app which reads all notification comes in device then stores that notification in Activity
contain ListView
and after that remove that notification from status bar. To do this I have used "NotificationListenerService
".
When I click ListView
that contain notification I want to open that notification in their target application. How do I do that?
Code I used:
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());
}
}
}
}