在Android中,如何让一个连接的蓝牙设备的配置文件? [英] In Android, how to get the profile of a connected bluetooth device?

查看:573
本文介绍了在Android中,如何让一个连接的蓝牙设备的配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过很多答案在这里,我可以用的广播接收器的帮助下建立连接的蓝牙设备的列表。现在的问题是我怎么知道哪些设备支持的配置文件。我希望能够挑选基于所述简档的设备,例如,获得当前连接的设备和他们的个人资料的列表,并选择其中之一。我不知道怎样才能获得这样的信息,如果我有BluetoothDevice类的实例。

Following a lot of answers here, I am able to build the list of connected bluetooth devices with the help of a BroadcastReceiver. Now my question is how do I know which device supports which profile. I want to be able to pick the devices based on the profile, for example, get a list of currently connected devices and their profile, and pick one of them. I don't see how I can get such info if I have the instance of BluetoothDevice.

在这个页面有一些codeS说明如何使用蓝牙耳机的曝光率:的 http://developer.android.com/guide/topics/connectivity/bluetooth.html#Profiles 。但它并没有解决我的问题。如果你觉得我缺少什么,请帮我指出来。

On this page there are some codes illustrating how to work with a bluetooth headset profile: http://developer.android.com/guide/topics/connectivity/bluetooth.html#Profiles. But it doesn't solve my problem. If you think I am missing anything, please help me and point it out.

非常感谢在前进。

推荐答案

我碰到了同样的问题。它不会出现,你可以从 BluetoothDevice类类获得可用的配置文件。
但是周围有一个很长的路通过得到的 BluetoothDevice类期从列表 getDevicesMatchingConnectionStates 方式在 BluetoothProfile

I've run into the same problem. It doesn't appear that you can get the available profiles from the BluetoothDevice class. But there is a long way around by getting a List of BluetoothDevices from the getDevicesMatchingConnectionStates method in the BluetoothProfile class.

例如,如果你想找到其中的 BluetoothDevice类的支持A2DP,首先创建一个自定义的 BluetoothProfile.ServiceListener

For example if you want to find which BluetoothDevices support A2DP, first create a custom BluetoothProfile.ServiceListener

public class cServiceListener implements BluetoothProfile.ServiceListener {
private static final int[] states={ BluetoothProfile.STATE_DISCONNECTING,
                                    BluetoothProfile.STATE_DISCONNECTED,
                                    BluetoothProfile.STATE_CONNECTED,
                                    BluetoothProfile.STATE_CONNECTING};
@Override
public void onServiceConnected(int profile, BluetoothProfile bluetoothProfile) {
List<BluetoothDevice> Devices=bluetoothProfile.getDevicesMatchingConnectionStates(states);
    for (BluetoothDevice loop:Devices){
        Log.i("myTag",loop.getName());
    }
}

@Override
public void onServiceDisconnected(int profile) {
}

}

然后将其连接到要检查的配置文件,在这个例子中A2DP

Then attach it to the profile you want to check, in this example A2DP

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
cServiceListener mServiceListener=new cServiceListener();
mBluetoothAdapter.getProfileProxy(thisContext,mServiceListener, BluetoothProfile.A2DP);

这将LogCat中的所有的支持A2DP蓝牙设备这是在要求状态。在这个例子中它包括当前连接的所有设备和previously配对设备的哪些是断开

This will logcat all the bluetooth devices that support A2DP which are in the requested states. In this example it includes all devices which are currently connected and previously paired devices which are disconnected.

这篇关于在Android中,如何让一个连接的蓝牙设备的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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