badaix / snapdroid

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

Control snapclient via broadcast intents #52

Closed chatziko closed 3 months ago

chatziko commented 1 year ago

This small PR allows the android snapcast client to be controlled (stop / start) by another app (or adb) via broadcast intents (de.badaix.snapcast.START_SERVICE / STOP_SERVICE).

For instance, one could stop the snapcast client via a Home Assistant notitification:

- service: notify.mobile_app_<your_device_id_here>
  data:
    message: "command_broadcast_intent"
    data:
      intent_package_name: "de.badaix.snapcast"
      intent_action: "de.badaix.snapcast.STOP_SERVICE"

or start the client from any remote script via adb:

adb connect <android-IP>
adb shell 'am broadcast -a de.badaix.snapcast.START_SERVICE de.badaix.snapcast'

I think it's a pretty useful feature to have, since many people use snapcast together with automation routines.

PS. To be able to use START_SERVICE when the app is in the background, one needs to select Allow background activity in the app's battery usage options.

mijofa commented 1 year ago

+1 for this pls. I just found this because I assumed it would already work and was searching for how to do it. Came across this instead, so I'm guessing it's not already possible.

mijofa commented 1 year ago

I decided to attack this again recently and after much confused bumbling around trying to make this Home Assistant service work:

service: notify.mobile_app_muir
data:
  message: command_activity
  data:
    intent_package_name: de.badaix.snapcast
    intent_class_name: .SnapclientService
    intent_action: ACTION_START
    intent_extras: EXTRA_HOST:harvest:String,EXTRA_PORT:1704:int

Despite this adb command working fine:

am start-service -f 0x10000000 --es EXTRA_HOST 'harvest' --ei EXTRA_PORT 1704 -a ACTION_START -p de.badaix.snapcast de.badaix.snapcast/.SnapclientService

I gave up and went for rebasing & compiling this pull request on the latest version of the app, confirmed it works well. Now when the device eventually OOM kills snapcast while it's muted and not doing anything, it'll start back up again when I actually want to unmute it anyway.

I believe this would be a very useful feature to include in the main upstream repo. Even without Home Assistant, this allows things like Tasker and many other automation tools to work with Snapdroid better while worrying less about Android's RAM management clearing up the process if it's muted for long periods of time.

chatziko commented 1 year ago

I rebased the PR to make it easier to merge. Personally I've been using it for some time now and it words great.

@badaix : please consider merging, it's a relatively simple change with many potential users (several have already expressed interest here).

badaix commented 1 year ago

Thanks! Will merge when I'm back from vacation.

mijofa commented 9 months ago

I see this one's still unmerged. Got any updates for us?

I would like this specific feature on my GoogleTV, but am a little stuck with apps available via the Play Store there.

chatziko commented 3 months ago

Maybe the upcoming v0.28 is a good opportunity to push this PR forward?