实践是知识的母亲,知识是生活的明灯。这篇文章主要讲述android 获取蓝牙已连接设备相关的知识,希望能为你提供帮助。
蓝牙如果手动配对并已连接,获取连接的设备:
【android 获取蓝牙已连接设备】1.检测连接状态:
java代码
文章图片
- int a2dp = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP);
- int headset = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);
- int health = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEALTH);
Java代码
文章图片
- int flag = -1;
- if (a2dp == BluetoothProfile.STATE_CONNECTED) {
- flag = a2dp;
- } else if (headset == BluetoothProfile.STATE_CONNECTED) {
- flag = headset;
- } else if (health == BluetoothProfile.STATE_CONNECTED) {
- flag = health;
- }
- if (flag != -1) {
- bluetoothAdapter.getProfileProxy(MainActivity.this, new ServiceListener() {
- @Override
- public void onServiceDisconnected(int profile) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onServiceConnected(int profile, BluetoothProfile proxy) {
- // TODO Auto-generated method stub
- List< BluetoothDevice> mDevices = proxy.getConnectedDevices();
- if (mDevices != null & & mDevices.size() > 0) {
- for (BluetoothDevice device : mDevices) {
- Log.i("W", "device name: " + device.getName());
- }
- } else {
- Log.i("W", "mDevices is null");
- }
- }
- }, flag);
- }
推荐阅读
- Dapper.net Insert mssql unicode 乱码问题
- web.xml中webAppRootKey
- word 2010 文档加密办法_Word专区
- Word 2010 不保存最近浏览文档 保护隐私_Word专区
- Word 2010 设置双面打印办法_Word专区
- word 2010 页边距设置办法_Word专区
- word 2010 打印浏览技巧_Word专区
- word 2010 撤销与恢复办法_Word专区
- Word 2010 字体颜色的设置_Word专区