How do you interact with a third-party notification in Android Studio?

Solution for How do you interact with a third-party notification in Android Studio?
is Given Below:

my goal is to interact with third-party notifications that appear in the status bar.

To interact with the notifications, I intend to programmatically simulate the user’s interaction with the UI, at least conceptually, then I think it will be a matter of sending an intent; I don’t want to have to manage gestures.

Typical situation :

  1. A notification appears on the status bar
  2. The notification is read and filtered (e.g. it has the com.telegram package)
  3. If the result is other than null, its content is clicked on

The follow-up is handled directly by the third-party app which normally opens the application after clicking on the content.

The strategy I had in mind:

  1. I set up a class that extends NotificationListenerService, which getActiveNotifications from StatusBarNotification.
    This should allow me to get the data of a notification once it appears.
  2. I do a check by filtering the information provided by the getActiveNotifications instance based on what I need.
  3. If the check is successful, in a class that extends BroadcastReceiver I take the notification’s intent and pass it to a PendingIntent through which I perform the action.

I’m pretty sure I’ve just made a lot of confusion, because I can’t put the pieces together from tutorials and answers found on the net.

I have only found a number of APIs that could help me, but I don’t know how to think about achieving the desired result.

Notification.Action

NotificationListenerService

NotificationManager

PendingIntent

BroadcastReceiver

AccessibilityService