Well It seems that you can see the notifications started by SL4A "como.googlecode.android_scripting" package with the following command:
This is more like a hack.
dumpsys statusbar | grep "pkg=com.googlecode.android_scripting"
Every notification initiated by SL4A will have an "id". For example the "id=1" is the notification started by SL4A when the server is running. The one you click to stop the server.
With this in mind you can can actually list every notification started by your package and block until the id of your notification disappear.
If so then your next notifications should have an id with 2 or above. Note that this can change if SL4A is stopped or crash. The next time you may get the "id=2" for the (RPC) server notification and then "id=3" and over for your app notifications until you restart your device and so the RPC server notification goes back to "id=1". Knowing this means that you need to keep searchig for new notifications within a loop.
For example in bash and using adb:
while read Info; do echo "$Info" | grep 'pkg=com.googlecode.android_scripting'; done < <(adb shell dumpsys statusbar)
You'll get something like this:
1: StatusBarNotification(pkg=com.googlecode.android_scripting id=2 tag=null score=0 notn=Notification(pri=0 contentView=com.googlecode.android_scripting/0x109008f vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) user=UserHandle{0}) # SL4A RPC Notification
7: StatusBarNotification(pkg=com.googlecode.android_scripting id=3 tag=null score=0 notn=Notification(pri=0 contentView=com.googlecode.android_scripting/0x109008f vibrate=null sound=null defaults=0x0 flags=0x10 kind=[null]) user=UserHandle{0}) # My Notification
Let's play with this!
Running:
while read Info; do echo "$Info" | grep "pkg=com.googlecode.android_scripting" | awk '{print $3}' | cut -s -d '=' -f2 ; done < <(adb shell dumpsys statusbar)
Will get you for example:
# Without Using Cut
id=2 # SL4A Notificaion
id=3 # My Notification
Or:
# Using Cut
2 # SL4A Notification
3 # My Notification
Let's get to the action! (An ugly solution)
# Start ADB USB Serial Connection
adb devices
# Activate Wireless ADB (Needs Root) - Not Needed
# adb shell setprop service.adb.tcp.port 5555
# stop adbd
# start adbd
Or:
# Start ADB Wireless
adb connect 192.168.1.3
NotifyCount=0
NotifyList=()
while read Notify; do
DumpNotify=`echo "$Notify" | grep "pkg=com.googlecode.android_scripting" | awk '{print $3}' | cut -s -d '=' -f2`
if [ ! -z "$DumpNotify" ] ; then
NotifyList[$NotifyCount]="$DumpNotify"
((NotifyCount++))
fi
done < <(adb shell dumpsys statusbar)
SL4ARPCNotification="2"
MyScriptNotification="3"
if [[ ${NotifyList[*]} != *"$MyScriptNotification"* ]] ; then
adb shell am start -a android.intent.action.MUSIC_PLAYER
fi
This should be better in 2 functions with arguments for MyNotification and SL4ARPCNotification variables. That way you can verify from anywhere in the code and divide the job: FunctionX for listing the notifications and FunctionY for comparing the results.
This can easily be done in Pyhon or other interpreters. You need to remember that there's always a notification from SL4A itself. By using Threading in python you can continuously search for new or old notifications without the need to block your program waiting for a change and thus you can continue runninig your script normally.