4

Android 8.0 and above brought notification channels. Is there any way to list all notification channels, create channels and/or disable channels for an app from ADB? Root solutions are acceptable too. Thank you.

SayantanRC
  • 608
  • 5
  • 19

2 Answers2

0

You can create a notification channel, delete a channel if you want using service call superuser command.

Here is a small example by which you can enable or disable notifications for any app. By using that reference you can get notification channels information.

public final Shell.Interactive su = new Shell.Builder().useSU().open();
function setNotification(String packageName, int uid, boolean enable){
    try {
          @SuppressLint("PrivateApi") Field field = Class.forName("android.app.INotificationManager").getDeclaredClasses()[0].getDeclaredField("TRANSACTION_setNotificationsEnabledForPackage");
          field.setAccessible(true);
          int id = field.getInt(null);
          su.addCommand(String.format(Locale.ENGLISH, "service call notification %d s16 %s i32 %d i32 %d", id, packageName, uid, enable ? 1 : 0));
   } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) {
          e.printStackTrace();
   }
}

here service call is used to call the underlying service, id is used to identify the function and s16 is for String input and i32 is for int input they are just parameters of the function we are calling in notification service.

You can find explanation to service call from here:

Where to find info on Android's "service call" shell command?

You can find reference to INotificationManager from here:

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/INotificationManager.aidl

As you can see there is a function called setNotificationsEnabledForPackage in the INotificationManager which I have used in the example. There are many functions related to notification channel like getNotificationChannel just use which suits you and replace it with setNotificationsEnabledForPackage and pass appropriate parameters.

Here su is from this library:

https://github.com/Chainfire/libsuperuser

RHS.Dev
  • 273
  • 4
  • 14
-1

You could try

adb shell dumpsys notification

This will show the detail about NotificationManagerService.

shreyasm-dev
  • 2,498
  • 5
  • 15
  • 32
cowboi-peng
  • 659
  • 2
  • 6
  • 23