Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control snapclient via broadcast intents #52

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

chatziko
Copy link
Contributor

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
Copy link

mijofa commented Mar 26, 2023

+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
Copy link

mijofa commented Jul 3, 2023

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 chatziko force-pushed the broadcast-intents branch from 175b890 to 7890f4a Compare July 3, 2023 08:38
@chatziko
Copy link
Contributor Author

chatziko commented Jul 3, 2023

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
Copy link
Owner

badaix commented Jul 3, 2023

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

@mijofa
Copy link

mijofa commented Sep 27, 2023

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
Copy link
Contributor Author

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

@badaix badaix changed the base branch from master to v0.28.0 April 5, 2024 08:44
@badaix badaix merged commit 58714f7 into badaix:v0.28.0 Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants