1
Completed

Change the notifications enabled/disabled status for an app (and channels and priority)

The now defunct Secure Settings plugin used to have a feature that allowed you to enable or disable notifications for an app. I eventually figured out that this can be set with root and the "service call" command, using the following as a reference for Pie https://android.googlesource.com/platform/frameworks/base/+/refs/heads/pie-release/core/java/android/app/INotificationManager.aidl

So for the app "com.my.app", you first need to get the uid:

stat -c "%u" /data/data/com.my.app

Then run the following to disable notifications:

service call notification 10 s16 "com.my.app" i32 app_uid i32 0

To re-enable them, run:

service call notification 10 s16 "com.my.app" i32 app_uid i32 1

You can also fetch the notification status by running:

service call notification 12 s16 "com.my.app" i32 app_uid

It's probably fine to disable the notifications if they're already disabled, and vice versa, but I always check first and run it only if necessary. The Secure Settings plugin did the same.

The number after "notification", in this case 10 and 12, change with each Android version. 10 and 12 are what Pie uses, and the above link can be used to look them up. "bool areNotificationsEnabledForPackage" is the 12th function listed under INotificationManager, and "void setNotificationsEnabledForPackage" is the 10th function listed. I'm not aware of any way to pull this from a running phone, and instead they have to be looked up in Android source. That's presumably why this feature in Secure Settings stopped working.

The other functions there can also be used to change notification priority for the app, along with working with the app's notification channels. I'm not sure how to best represent the app's notification channels in the Tasker UI, but a simple action to just enable or disable an app's notifications would be really convenient.

3 replies

This can already be done with the AutoNotification Categories action :)

I

Thanks! I didn't know this was there.

How do you filter by certain channels in apps, when the channel names are duplicated under different groups? For example, Hangouts has the same channels for each Google account, with them grouped under each email address. ie, email1@gmail.com: Messages, Incoming calls. email2@gmail.com: Messages, Incoming calls. 

Just like Tasker has 2 sets of channels, one under User and one under System. If for example I had the Monitor channel under both User and System, how do I match just the one under User?

I

This no longer works on Android 10

It still works for me. What exactly doesn't work for you? Do you get an error?

I

No error, it just doesn't work. Using the same Tasker profile, the notifications for the app remain enabled (confirmed by looking at the Notification permissions on the app). If I disable them there, then try to re-enable them via AutoNotification, again nothing happens and they remain disabled.

Likewise, "service call" no longer seems to work, when updated for 10. The call to return whether a notification is enabled or not always returns false / not enabled. And the command to enable/disable them does nothing. Though a few times when trying to enable them, it disabled them instead for some reason. But generally it has no effect, neither disabling or enabling. So it could be a bug in 10?

Can you please export your task's description (not xml) so I can take a look? Long-click the task in Tasker->export description Thanks in advance

I

    Test Notifications Disable (348)

     A1: AutoNotification Block [ Configuration:Apps: com.google.android.talk

    Toggle: Enable Timeout (Seconds):60 ] 

    

Hi again. You're supposed to use the AutoNotification Categories action, not the Block one :)

LF

In Android 10 we cannot change notification importance anymore, right?