9

I have an Android(7) phone [also fine if you can provide a solution for Android 10] and a Linux pc. By enabling USB debugging and using the terminal of my pc, I am able to read the notifications of my phone using the command: adb shell dumpsys notification --noredact

Now, there are some notifications in android in which we can interact with the app directly from the notification. For example, in a Whatsapp notification, there are usually two buttons: Reply & Mark as read. In YouTube, there are options like Play, Turn off, Watch later. In the output of the above command, these options are visible in the following form:

actions={
        [0] "Reply" -> PendingIntent{6becf48: PendingIntentRecord{87b8050 com.whatsapp startService (whitelist: +30s0ms)}}
        [1] "Mark as read" -> PendingIntent{c1661e1: PendingIntentRecord{b8e3249 com.whatsapp startService (whitelist: +30s0ms)}}
      }

I have two questions:

  1. Can we interact with these options from adb shell? For example, is there any command like adb shell <SOME COMMAND> 'Message to be sent in whatsapp with reply option' which will send the text as a reply in whatsapp without opening the app?

  2. Is it possible to swipe the notifications using any adb command? (Not the adb shell input swipe x0 y0 x1 y1, it requires to unlock the phone each time)

Thank you in advance!

Edit:

Here is what I found that may be relevant to this question.

I think that I have to somehow launch the specific intent linked to the mentioned PendingIntent id (in this case 6becf48 or 87b8050)

Using tthe command adb shell dumpsys activity intents > output.txt and then searching for 87b8050 in output.txt, I found the name of the intent. It was as follows:

  * PendingIntentRecord{87b8050 com.whatsapp startService (whitelist: +30s0ms)}
    uid=10104 packageName=com.whatsapp type=startService flags=0x0
    requestIntent=act=com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE dat=content://com.whatsapp.provider.contact/contacts/2256 cmp=com.whatsapp/.notification.DirectReplyService (has extras)
    whitelistDuration=+30s0ms

Now I think that it may be possible to launch the intent com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE using adb shell am command, and passing the intent id and message as some parameters.

(Just like we can launch Whatsapp from adb with am command, it should be possible to launch the pendingIntent also.)

Edit 2:

Using this command:

adb shell am startservice -a com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE -d content://com.whatsapp.provider.contact/contacts/2256 -n com.whatsapp/.notification.DirectReplyService --es 'com.whatsapp.Intent.EXTRA_TEXT' 'Hi. Okay.'

The output was following:

Starting service: Intent { act=com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE dat=content://com.whatsapp.provider.contact/contacts/2256 cmp=com.whatsapp/.notification.DirectReplyService (has extras) }
Error: Requires permission not exported from uid 10104

12
  • 1
    I too am interested in this question.. I currently use "Automate" app for automatically interacting with my notifications(if that helps)
    – Aayush
    Oct 30 '20 at 15:47
  • Thanks for the information, I shall check this out. But as it seems, the app requires a lot of permissions. It'd be nice if we can do it from our adb terminal.
    – Soham Saha
    Oct 30 '20 at 16:27
  • No, it doesn't. That's what i like about this app. Just deny all the permissions at the start and then afterwards it will ask for one or two necessary permissions. I too am too paranoid about my privacy. This app lists all the permissions it has and you can anytime revoke permissions you don't want anymore. Disable the internet access for additional security. I'll search about the adb thing too tho.. BTW why dont you try scrcpy(just for fun). I just love scrcpy and use it very often with adb over wifi. github.com/Genymobile/scrcpy
    – Aayush
    Oct 30 '20 at 17:47
  • 1
    I understand that this has not been mentioned explicitly anywhere. But I still believe this is doable. Please see my recent edit to the question.
    – Soham Saha
    Oct 31 '20 at 5:42
  • 1
    Also, there is this KDEConnect app (see Reply to Whatsapp and others subheading) which seems to promise replying to WhatsApp from your PC. I know it can sync notifications but I never tried its reply feature. You can give it a try.
    – Firelord
    Nov 10 '20 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.