Android 蓝牙获得连接设备的Mac地址和名称
2016-09-07 18:48
429 查看
adapter = BluetoothAdapter.getDefaultAdapter(); int a2dp = adapter.getProfileConnectionState(BluetoothProfile.A2DP); int headset = adapter.getProfileConnectionState(BluetoothProfile.HEADSET); int health = adapter.getProfileConnectionState(BluetoothProfile.HEALTH); int flag = -1; if (a2dp == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "onCreate:1 "+a2dp); flag = a2dp; } else if (headset == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "onCreate:2 "+headset); flag = headset; } else if (health == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "onCreate:3 "+health); flag = health; } if (flag != -1) { adapter.getProfileProxy(MainActivity.this, new BluetoothProfile.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()+";"+device.getAddress()); } } else { Log.i("W", "mDevices is null"); } } }, flag);
相关文章推荐
- android设备连接蓝牙外设导致activity重启(recreate)的问题
- Android蓝牙开发之连接设备
- android当蓝牙设备连接或者断开时候的广播事件处理
- 关于Android蓝牙设备的连接使用
- Android Bluetooth蓝牙开发:Bluetooth蓝牙设备之间的连接建立(3)
- android蓝牙开发 蓝牙设备的查找和连接
- 如何获得Android设备名称(ADB命令详细介绍)
- Android 蓝牙设备的查找和连接
- WINCE蓝牙服务器获得被其他设备连接信息
- Android 蓝牙设备的查找和连接
- Android爪机连接蓝牙设备并进行通信的小例子
- Android蓝牙开发之自动连接设备
- android蓝牙串口连接固定Mac地址,省略搜索过程的实现
- android蓝牙开发 蓝牙设备的查找和连接
- Android 蓝牙设备的查找和连接
- Android蓝牙连接汽车OBD设备
- Android 蓝牙设备的查找和连接
- Android 不连接蓝牙设备获取信号强度
- 【转】android蓝牙开发 蓝牙设备的查找和连接
- Android中连接蓝牙设备时遇到createRfcommSocketToServiceRecord的UUID问题和BluetoothSocket的connect失败