2014-01-23 29 views
1

我想制作一个蓝牙广播接收器,它只对连接到蓝牙免提车载套件有反应。但我不知道如何过滤掉它。蓝牙广播接收器,如何获得BleutoothClass

有没有什么办法可以获得BluetoothClass.Device出于意图,还是另一种获得它的方式?

我从下面的东西开始,但我没有找到正确的方法。 一此外,以下如果块当您从设备断开被称为(仅适用没有这个final int state = intent.getIntExtra(???);

if (action.equals("android.bluetooth.device.action.ACL_CONNECTED")) {  
    final int state = intent.getIntExtra(???); 
} 

希望你能帮助我,坦克给大家。


SOLUTION:

BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 

int btClass = device.getBluetoothClass().getDeviceClass(); 

if (btClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE|| btClass == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO){...} 

回答

0

你想监听BluetoothHeadset过滤器以注册您的广播接收器.ACTION_CONNECTION_STATE_CHANGED(BluetoothHeadset类用于耳机和免提配置文件)。您还需要将BLUETOOTH权限添加到清单。

这只会让你改变连接,所以你必须使用蓝牙API来判断它是连接还是断开。

要获取设备,可以使用BluetoothHeadset.getDevicesMatchingConnectionStates(int [] states)获取所有连接的设备的列表。

+0

谢谢,但那不是我所搜索的。 – MEX