MishaP
MishaP

Reputation: 157

How do I clear notifications using ADB shell

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.

Upvotes: 7

Views: 14643

Answers (2)

sromku
sromku

Reputation: 4683

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

Upvotes: 6

Alex P.
Alex P.

Reputation: 31716

Try:

adb shell service call notification 1

Upvotes: 10

Related Questions