Macrodroid shell script ADB command app notifications

FireDroid

New member
Hello,

I'm looking for a way to enable/disable app specific notifications (for normal apps, not for system apps) like you can do it in Android settings (Settings -> Apps -> [AppName] -> Notifications - > ...) . As far as I know, this might be best (and maybe only) done via a Macrodroid shell script invoking ADB commands. Since I haven't managed to do it until now - could someone please help me? I'm using Android 12, not rooted.

Thanks!
 

Attachments

  • 2023-08-16 10_45_28-Clipboard.png
    2023-08-16 10_45_28-Clipboard.png
    251.7 KB · Views: 10
  • 2023-08-16 10_47_36-Clipboard.png
    2023-08-16 10_47_36-Clipboard.png
    202.8 KB · Views: 10

Endercraft

Moderator (& bug finder :D)
Do you have something like adb tcpip configured ?
We have threads here that explain how to setup adb commands.
 

FireDroid

New member
I'm testing my adb commands via PC/cable, this works fine.
What I'm looking for is which adb command/action/intent/... i have to use for enabling/disabling the shown notification settings...
 

Dimlos

Well-known member
In Android 13, there seems to be an adb command to switch notifications, but in Android 12 it seems impossible.
Maybe the only way is to use UI interaction.
 

Dimlos

Well-known member
adb shell pm revoke PACKAGE_NAME android.permission.POST_NOTIFICATIONS
adb shell pm grant PACKAGE_NAME android.permission.POST_NOTIFICATIONS
The command I searched for seems incomplete.
The toggles do not function properly and start working the next time I touch them.
 

Endercraft

Moderator (& bug finder :D)
You can always clear notifications the instant they come, but I think UI Interaction is the way to go. You'd need to know what command MacroDroid runs with root..
 

FireDroid

New member
What I found was

adb shell am start -a android.settings.APP_NOTIFICATION_SETTINGS --es android.provider.extra.APP_PACKAGE net.superblock.pushover

to open the exact settings page, it works fine. I thought if I can already open the page maybe there is an intent/action that can change the setting...but I can't find anything :(
 

Endercraft

Moderator (& bug finder :D)
Try using adb shell input keyevent (keyevent).
You can find lists of keyevents online to navigate.
 

sampleuserhere

Active member
I don't think it's possible without either ADB WiFi or Root. Tasker could only do it with either one of those privileges by executing the following code.

Code:
notification.setNotificationsEnabledForPackage(package_name, uid,1/0)

The low-key workaround would be to disable the notification categories of the target app with third party plugin, like Notification Listener or Autonotification.
 

Endercraft

Moderator (& bug finder :D)
I don't think it would be possible. Either Tasker restricts every notification channel or it gets every notification then snooze/delete them - but adb is not necessary for this..

Screenshot_2023-08-16-17-09-05-121_com.termux-edit.jpg
Commands (screenshot is hard to read) :

allow_listener COMPONENT [user_id (current user if not specified)]

disallow_listener COMPONENT [user_id]

allow_assistant COMPONENT [user_id]

remove_assistant COMPONENT [user_id]

set_dnd [on|none (same as on)|priority|alarms|all|off (same as all)]

allow_dnd PACKAGE [user_id]

disallow_dnd PACKAGE [user_id]

reset_assistant_user_set [user_id]

get_approved_assistant [user_id]

post [--help | flags] TAG TEXT

set_bubbles PACKAGE PREFERENCE (0=none 1=all 2=selected) [user_id]

set_bubbles_channel PACKAGE CHANNEL_ID ALLOW [user_id]

list

get
<notification-key>

snooze --for <msec> <notification-key>

unsnooze <notification-key>


It would be a good idea to ask the Tasker developer.
 

Endercraft

Moderator (& bug finder :D)
OK I can run the command in adb shell but it says /system/bin/sh: syntax error: unexpected 'something' every time I try something.
 

sampleuserhere

Active member
That's the part I exactly have no idea about. It looks like a function syntax in Java or Javascript instead of bash. So it may not be executable in other environment, but that's just my guess.

If OP were on Android 13, he could rely on Dimlos's suggestion. Post notification permission was just recently introduced in A13 after all.

I guess if OP wants to do the job fully in background, he doesn't really have much choices but to snooze the notification or edit the category importance.
 

sampleuserhere

Active member
I've just found out that POST_NOTIFICATION is also exposed via appops.appops set com.whatsapp POST_NOTIFICATION allow

Maybe you may have a shot with this, by setting the value to ignore. You can grab the other listed permissions as well by running the following code appops get com.whatsapp.
 
Top