badaix / snapdroid

Snapcast client for Android
GNU General Public License v3.0
124 stars 25 forks source link

Start/ Stop client with ADB #54

Closed tabearunzheimer closed 1 year ago

tabearunzheimer commented 1 year ago

Hey there, I really love your project. I've been using Snapcast for a while now and due to a recent update on my setup I've been wondering if there is a way to control snapdroid with adb commands. I am able to start and stop the app itself but I was hoping I could turn on/off the client as well. I'm planning on building my device into another setup so this would be immensely helpful. Otherwise I would always have to dis- and reassemble everything, if the client stops.

According to the SnapclientService.java and MainActivity.java files, I figured the intent must be something like ACTION_START or ACTION_STOP, but it doesn't work. The closest reaction I've got, seemed to be reopening the MainActivity on top of the existing one.

adb shell am broadcast -a android.intent.action.ACTION_START -d de.badaix.snapcast/.MainActivity --es "<snapserver-ip>" --ei 1704

Any help on this is highly appreciated.

tabearunzheimer commented 1 year ago

I figured it out, so for everyone else interested:

# start snapclient
adb shell am startservice --es EXTRA_HOST '<snapcast-server>' --ei EXTRA_PORT <snapcast-port> -f 0x24000000 -a ACTION_START -n de.badaix.snapcast/.SnapclientService
# stop snapclient
adb shell am startservice --es EXTRA_HOST '<snapcast-server>' --ei EXTRA_PORT <snapcast-port> -f 0x24000000 -a ACTION_STOP -n de.badaix.snapcast/.SnapclientService
# example values
adb shell am startservice --es EXTRA_HOST '192.168.178.30' --ei EXTRA_PORT 1704 -f 0x24000000 -a ACTION_START -n de.badaix.snapcast/.SnapclientService

Technically, it should be stopservice to stop snapclient, but it works both ways. Just make sure to change the action (-a ACTION_START or -a ACTION_STOP). Hope this helps someone else.