How to write a program to connect to bluetooth a2dp device using Android 3.0?

My app needs to connect to a2dp device via bluetooth, and I want to "be able to query visible bluetooth devices and then select a2dp device and connect via a2dp" so that the sound starts playing through the connected device ", but a gingerbread strand is working on my phone ( 2.3.3).

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

"Starting with 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 is stackoverflow marker programmatically failing ?!) to connect to a2dp device using pre-3.0 android version? Is my only way to direct the user to their settings / pull settings programmatically? Since I can do this through settings, I guess I just assumed it was possible with my application as well.

reference

+1


source to share


2 answers


Some of the Bluetooth classes (profiles such as BluetoothA2dp) are hidden in Gingerbread. This means that their declaration is annotated with @hide and they are not included in the SDK (Android.jar). This is intentional as these APIs are likely to change in newer versions of Android. It is generally not recommended to use hidden APIs as your application might stop working with newer versions of Android, 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 have 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);
    }
}

      

+2


source


So after much more research, it seems that it is not possible to programmatically connect to an A2DP device on an Android device prior to 3.0. I will mark this as an answer, but if anyone finds something else, please correct me on this as I would really like to do this programmatically.



0


source







All Articles