2
votes

My application needs to connect to a a2dp device over bluetooth and I want to "be able to query for the visible bluetooth devices, then, select a a2dp device and have it 'connect via a2dp' so that audio starts playing through the connected device" but my phone is running gingerbread (2.3.3).

I went through the basic bluetooth tutorial at http://developer.android.com/guide/topics/wireless/bluetooth.html and got to the part I need to connect to the bluetooth device and then I read the bottom of the page:

"Starting in Android 3.0, the Bluetooth API includes support for working with Bluetooth profiles." -> does this mean that I am S.O.L.? Is there any way to programmatically (why does stackoverflow mark programmatically as being misspelled?!) connect to a a2dp device using a pre-3.0 version of Android? Is my only option to direct the user to go into their settings/pull up the settings programmatically?? Because I'm able to do it through the settings, I guess I just assumed it would be possible via my application as well.

Help?

2
btw, I tried 'connecting' to the 'ServerSocket' (in hopes that I might be able to connect) but it never seems to make the connection (I don't see the little things next to the bluetooth icon on my phone, etc.) even though nothing seems to fail. This is because I need to somehow use the profile, correct? Or, maybe I'm doing something wrong? (my code is essentially exactly like the google bluetooth tutorial)fatfreddyscat

2 Answers

2
votes

Some of the Bluetooth classes (profiles like BluetoothA2dp) are hidden in Gingerbread. It means that their declaration is annotated by @hide, and they are not included into the SDK (Android.jar). This is done intentionally, since these APIs are likely to be changed in newer Android versions. Generally it is not a good idea to use hidden APIs, since your App can stop working on newer Android versions, but if you are sure you want to, follow http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/

Once you get access to them do something like (just a hint):

BluetoothA2dp mBluetoothA2dp = new BluetoothA2dp(context);
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().
// Loop through paired devices
for (BluetoothDevice device : mBluetoothAdapter.getBondedDevices()) {
    if (device.getName().contains("whatyouwant")) {
        mBluetoothA2dp.addSink(device);
    }
}
0
votes

So, after much more research, it seems that it is impossible to programmatically connect to a A2DP device on a pre-3.0 Android device. I am going mark this as the answer but, if someone finds otherwise, please correct me on this as I would really like to do it programmatically.