How do I clear notifications using ADB shell

10,246

Solution 1

Try:

adb shell service call notification 1

Solution 2

If you know the type of the device and Android version, you can clear notifications using ADB without having rooted device.

The idea is to pull down notifications and swipe away all notifications one by one.

  1. Pull down:

    adb shell input swipe 0 0 0 300
    
  2. Swipe away:

    adb shell input swipe 0 400 300 400
    

It is important to mention, that the (x,y) is something that vary between different type of devices and Android versions. You will need to find by several checks what is the best x,y for you.

The full script

adb shell input swipe 0 0 0 300
num=$(adb shell dumpsys notification | grep NotificationRecord | wc -l)
echo $num
while [ $num -gt 0 ]; do
    adb shell input swipe 0 400 300 400
    num=$(( $num - 1 ))
done

More details can be found here: https://www.sromku.com/blog/android-adb-clear-notifications

Share:
10,246
MishaP
Author by

MishaP

Updated on June 16, 2022

Comments

  • MishaP
    MishaP almost 2 years

    I know I can unlock the screen, pull down the notifications, and press the clear notifications button, but there's got to be a way to clear the notifications through ADB, right? I'm guessing it's some Intent sent through the 'am' command, or maybe something even simpler, but I can't seem to find anything on the net. All I'm getting is Java code for use with an apk.

    Edit: I should probably mention that I'm running on 4.3, sometimes commands may vary between versions.

  • MishaP
    MishaP over 10 years
    $ adb shell service call notification 1 Result: Parcel(fffffffc ffffffff '........')
  • Alex P.
    Alex P. over 10 years
    you need root to use service commands. other than that it should work in 4.3 no problem
  • MishaP
    MishaP over 10 years
    thank you, accepted answer. Instead of restarting the device in root, I used su -c: adb shell su -c service call notification 1
  • Corey Ogburn
    Corey Ogburn over 10 years
    @MishaP: It might just be me, but I think you have to wrap service call notification 1 in quotes to make su -c work.
  • Piotr Zawadzki
    Piotr Zawadzki about 4 years
    I've tried it and in my case it did not work, because not all notifications can be dismissed e.g. Android Wizard notification that might appear when starting the device for the first time. See: developer.android.com/reference/android/app/…