Use Tasker to toggle Bluetooth Device Settings

1,803 views
Skip to first unread message

HMATP

unread,
Oct 20, 2011, 7:47:56 PM10/20/11
to Tasker
Inspired by Matthieu Berthomé's work in using Tasker to start a
service in CyanoGen Mod: http://groups.google.com/group/tasker/browse_thread/thread/559a6e17ba3ede0b#

I thought I would ask if anyone could think of a way to use it to
toggle the settings for the various devices registered for Blurtooth
(ie. Phone and/or Media Audio)?

Basically I want to be able to tell the phone to toggle Phone Audio on
or off for my BT headset depending on wheather or not it also
connected to my vehicle BT while still leaving the headset connected
for Media Audio.

Matthieu Berthomé

unread,
Oct 21, 2011, 6:24:24 AM10/21/11
to tas...@googlegroups.com
I don't have bluetooth headsets to test it, but tell me, when in the bluetooth settings there are some devices paired, you can open settings for each device, and toggle the profiles from there ?
I'll dig into the bluetooth settings source code to try and find something ;-)

Matthieu Berthomé

unread,
Oct 21, 2011, 8:14:18 AM10/21/11
to tas...@googlegroups.com
Digging... digging...
In this
http://www.google.com/codesearch#cZwlSNS7aEw/packages/apps/Settings/src/com/android/settings/bluetooth/&type=cs
for everything bluetooth
ConnectSpecificProfilesActivity is the code for the activity that does the specific profiles connection/deconnection
It's only an activity, without any broadcast receiver or anything. But you can call this activity, with Tasker, to bring up the profile connection/deconnection when needed, maybe.
This activity queries a CachedDevice, with a connect(profile) command, which queries a
LocalBluetoothProfileManager.connect for this specific profile and device. I've still got some digging to do ;-)

Matthieu Berthomé

unread,
Oct 21, 2011, 10:44:47 AM10/21/11
to tas...@googlegroups.com
each profile is associated with a given profilemanager, HeadsetProfileManager, A2dpProfileManager, etc.
When you connect your BT headset, what do you see in the profile settings ? I'd say A2DP corresponds to media audio and Headset to Phone audio, but I'm not sure.
For A2DP:
A2dpProfileManager.connect launches a mService.connectSink(device) where mService is a BluetothA2DP object, which interfaces with the bluetoothA2DP private system API. The interface gets written on. So the trick is to initiate this interface writing from Tasker, or interface with the private system API.
Interface with the private system API can be hacked into a user app with some difficulties, but apparently doable (I've seen some code for accessing hidden private GPS API). SL4A might have some stuff to write to interfaces or interface with the system API.
System API is described there http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/java/android/bluetooth/&type=cs&q=IBluetoothA2dp%20&exact_package=android
For now, it's all I've got. No easy intent way to do it :'(


HMATP

unread,
Oct 24, 2011, 12:21:14 AM10/24/11
to Tasker
2 check boxes.
One says; Phone. Use for phone audio. (this is the one I want to
change)
The other; Media. Use for media audio.

The vehicle BT device only has the the Phone check box.

Thanks for digging!

Definately looks like ConnectSpecificProfilesActivity is where I want
to be.

Interesting here

/**
* Gets the summary that describes when checked, it will become a
preferred profile.
*
* @param profile The profile to get the summary for.
* @return The summary.
*/

Wonder what might be contained in @param & if there is anyway to
manually build a set of them with different options that Tasker could
then switch out depending on which options you want?


On Oct 22, 1:44 am, Matthieu Berthomé <matthieu.berth...@gmail.com>
wrote:
> each profile is associated with a given profilemanager,HeadsetProfileManager,
> A2dpProfileManager, etc.
> When you connect your BT headset, what do you see in the profile settings ?
> I'd say A2DP corresponds to media audio and Headset to Phone audio, but I'm
> not sure.
> For A2DP:
> A2dpProfileManager.connect launches a mService.connectSink(device) where
> mService is a BluetothA2DP object, which interfaces with the bluetoothA2DP
> private system API. The interface gets written on. So the trick is to
> initiate this interface writing from Tasker, or interface with the private
> system API.
> Interface with the private system API can be hacked into a user app with
> some difficulties, but apparently doable (I've seen some code for accessing
> hidden private GPS API). SL4A might have some stuff to write to interfaces
> or interface with the system API.
> System API is described therehttp://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/jav...

HMATP

unread,
Oct 24, 2011, 12:56:21 AM10/24/11
to Tasker
Actually it would be the values in @return I need to switch out.

Gathered here (I think)

private static int getProfileSummary(LocalBluetoothProfileManager
profileManager,
Profile profile, BluetoothDevice device, int
connectionStatus, boolean onlineMode) {
if (!onlineMode || connectionStatus ==
SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED) {
return getProfileSummaryForSettingPreference(profile);
} else {
return profileManager.getSummary(device);
> > For now, it's all I've got. No easy intent way to do it :'(- Hide quoted text -
>
> - Show quoted text -

Matthieu Berthomé

unread,
Oct 24, 2011, 8:14:46 AM10/24/11
to tas...@googlegroups.com
@param is just for the javadoc to understand the source and create a documenation. The parameter is profile, which is a Profile. A Profile is defined in LocalBluetoothProfileManager, this is basically an enum of strings. To switch, say A2DP (media audio) profile, you'd pass it the parameter Profile.A2DP. But to access these function from an external source (Tasker) is not something I know how to do.
There is a public API for bluetooth profiles http://developer.android.com/reference/android/bluetooth/BluetoothProfile.html . But apparently no way to toggle profiles.
I'm running out of way to dig ;-) Look up SL4A and the bluetooth facades they might have. Maybe they have something.

Reply all
Reply to author
Forward
0 new messages