Sunday, March 5, 2017

How to Disable Bluetooth Automatic Playback on any Android Phone

Have you ever connected your phone to your favorite Bluetooth speaker or car kit and found that applications like Google Play Music, Pandora, or Soundcloud automatically start playing?

This can be quite annoying for those users who would prefer to select their own preferred application for media playback. Unfortunately, unless your particular Bluetooth device allows you to disable auto-play, then there’s little you can do to prevent the playback command being sent to your device.

If you search for solutions to this problem on the web, you may have come across a few pages that suggest a rather crude method to solve this issue. It involves going into the Bluetooth profiles settings page for each particular Bluetooth device and disabling the media audio profile. I call this a “crude” solution because, while it does prevent auto-playback, you have to manually go back and re-enable this profile before you can use your Bluetooth device for media playback again.

Bluetooth Profiles

However, there’s a better method that you can use to solve this problem. If you’ve read any of my previous tutorials, then you’ve probably already guessed that this involves the use of Tasker. This time, though, you won’t need to use any other application/plug-in, and the solution is fairly simple to implement even for beginner Tasker users. Here’s how it’ll work.


Understanding Bluetooth Autoplay on Android

What essentially happens when you connect a Bluetooth device that sends an autoplay command is that this command is seen as a KeyEvent for toggle play/pause in Android. Applications with a MediaButtonReceiver broadcast receiver can then react to this Media Button event.

But if you have multiple applications that can react to this intent, how does Android know which application to actually start playback? How it works is that Android keeps track of the last application that requests to receive Media Button events. Any new media application can take over to listen to Media Button key events by calling setMediaButtonReceiver in AudioManager, and that application will handle Media Button key events until another application requests control. You can actually see which application is currently set to respond to these key events by entering the following ADB command:

adb shell settings get secure media_button_receiver

On my device, this command yielded the following output:

com.google.android.music/com.google.android.music.playback.MediaButtonIntentReceiver

This is the broadcast receiver set up by Google Play Music to respond to Media Button key events. So if I plug in my Bluetooth device, my phone will automatically start playback in Google Play Music.

We can take advantage of this fact by having Tasker be the one to respond to Media Button key events. That way, Tasker will absorb the toggle play/pause command, preventing any other application from reacting to it and thus starting playback. Now, here’s how it’s done.


Disable Bluetooth Autoplay with Tasker

As mentioned before, you’ll need Tasker for this project. You won’t need any additional plugins this time around, though. I’m not sure how you can replicate this on other automation applications as I’m not familiar with their feature-set, but you’re free to try it out.

First up, open up Tasker and create a new profile by pressing on the + icon. Choose the State context as shown below and pick Net –> BT Connected. Here, press the magnifying glass icon under either the Name or Address field and choose all of the Bluetooth devices you want to prevent automatic playback on.

Next up, we’ll need to create our Task. No need to bother with naming it, as there’ll only be a single Action here and it won’t be used in another Profile. Once you’re in the Task creation screen, press on the + button in the bottom middle of the screen to create an Action. Go to Media –> Media Button Events and choose Grab in the dropdown menu. In my experience, I didn’t need to select “Use New API”, but if in the end this project doesn’t work, you can go back and enable this checkbox.

Once you’re done, Tasker should now automatically set itself as the Media Button Receiver in Android upon connection to your selected Bluetooth devices. This way, the play/pause action that is sent will not be received by any of your media applications, but instead by Tasker.

Don’t worry, though, as this doesn’t mean that Tasker will continue grabbing Media Button key events indefinitely. As mentioned previously, any application can request to do this, so when you manually start playback on your desired media player of choice, it will then take back control of listening to Media Button key events.


Conclusion

I obviously can’t test this on every device, but I’ve tested it numerous times by having this profile enabled/disabled and connecting/disconnecting my Bluetooth device repeatedly. It worked as I expected it to, but you’ll have to try it out on your own.

This time I won’t be providing a profile for you to import due to the fact that this profile is both incredibly easy to set up and also requires you to manually change the Profile to pick your own Bluetooth devices anyways. Do let me know if this profile works for you, though, and/or if you have any suggestions for improvements!

HostGator Web Hosting

0 comments:

Post a Comment