如何编写程序以使用 pre 3.0 Android 连接到 a2dp 蓝牙设备? [英] How write a program to connect to a a2dp bluetooth device using pre 3.0 Android?

查看:23
本文介绍了如何编写程序以使用 pre 3.0 Android 连接到 a2dp 蓝牙设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要通过蓝牙连接到 a2dp 设备,我希望能够查询可见的蓝牙设备,然后选择一个 a2dp 设备并让它‘通过 a2dp 连接’,以便音频开始通过连接的设备",但我的手机正在运行姜饼 (2.3.3).

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).

我在 http://developer.android 上完成了基本的蓝牙教程.com/guide/topics/wireless/bluetooth.html 并到达了我需要连接到蓝牙设备的部分,然后我阅读了页面底部:

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:

从 Android 3.0 开始,蓝牙 API 支持使用蓝牙配置文件."-> 这是否意味着我是 S.O.L.?有没有办法以编程方式(为什么以编程方式将 stackoverflow 标记为拼写错误?!)连接到使用 3.0 之前版本的 Android 的 a2dp 设备?我是指导用户进入他们的设置/以编程方式拉出设置的唯一选择吗?因为我可以通过设置来做到这一点,我想我只是假设它也可以通过我的应用程序来实现.

"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.

帮助?

推荐答案

一些蓝牙类(配置文件如 BluetoothA2dp)隐藏在 Gingerbread 中.这意味着它们的声明由@hide 注释,并且它们不包含在 SDK (Android.jar) 中.这是有意完成的,因为这些 API 可能会在较新的 Android 版本中进行更改.通常使用隐藏的 API 不是一个好主意,因为您的应用程序可能会停止在较新的 Android 版本上运行,但如果您确定要这样做,请遵循http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/

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

这篇关于如何编写程序以使用 pre 3.0 Android 连接到 a2dp 蓝牙设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆