如何使用BluetoothHeadset API来获取蓝牙连接设备 [英] How to get bluetooth connected devices using BluetoothHeadset API

查看:4326
本文介绍了如何使用BluetoothHeadset API来获取蓝牙连接设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的蓝牙连接的设备......不只是配对的设备列表。

I want to get list of bluetooth connected devices...not just paired devices.

我发现 BluetoothHeadset 在API API级别11 ,它提供的方法 getConnectedDevices()获取连接的蓝牙设备列表。

I found BluetoothHeadset API in API level 11 which provides method getConnectedDevices() to get list of connected bluetooth devices.

如何使用这个API蓝牙连接的设备列表?

How to get list of bluetooth connected devices using this API ?

推荐答案

终于得到了解决....下面是正确的code获取蓝牙音频连接设备使用 BluetoothHeadset API

Finally got the Solution....Below is correct code for getting Bluetooth audio connected devices using BluetoothHeadset API.

BluetoothHeadset mBluetoothHeadset;

// Get the default adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

// Establish connection to the proxy.
mBluetoothAdapter.getProfileProxy(context, mProfileListener, BluetoothProfile.HEADSET);


// Define Service Listener of BluetoothProfile
private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
    if (profile == BluetoothProfile.HEADSET) {
        mBluetoothHeadset = (BluetoothHeadset) proxy;
    }
}
public void onServiceDisconnected(int profile) {
    if (profile == BluetoothProfile.HEADSET) {
        mBluetoothHeadset = null;
    }
}
};


//call functions on mBluetoothHeadset to check if Bluetooth SCO audio is connected.
List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();                        
for ( final BluetoothDevice dev : devices ) {           
     return mBluetoothHeadset.isAudioConnected(dev);
}


// finally Close proxy connection after use.
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);

这篇关于如何使用BluetoothHeadset API来获取蓝牙连接设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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