开发者

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

开发者 https://www.devze.com 2023-04-11 13:53 出处:网络
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

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 t开发者_如何转开发o 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?


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);
    }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号