0

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());
            }
        }
    }


}
halfer
  • 19,824
  • 17
  • 99
  • 186
Raghav
  • 65
  • 1
  • 12

1 Answers1

0

You can check out this link , But i have used it so am not sure it work for you or not but as per description it provide

  • getId
  • getNotification
  • getPackageName
  • getPostTime

from above you can use getPackageName to open target application

Anil
  • 1,087
  • 1
  • 11
  • 24