蓝牙如果手动配对并已连接,获取连接的设备:

1.检测连接状态:

int a2dp = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.A2DP);int headset = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET);int health = bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEALTH);

2,根据是否有连接获取已连接的设备:

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() {@Overridepublic void onServiceDisconnected(int profile) {// TODO Auto-generated method stub}@Overridepublic void onServiceConnected(int profile, BluetoothProfile proxy) {// TODO Auto-generated method stubList<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);}

更多相关文章

  1. android 蓝牙writeCharacteristic不成功
  2. android获取版本信息、屏幕信息和设备编号
  3. Android 三星128G SD卡格式化为内部存储设备,显示为256G
  4. cryptfs-password-manager, Android设备加密密码管理器
  5. 判断android设备是否支持硬解码
  6. android之蓝牙开发
  7. ueventd.rc 处理硬件设备权限和android init 对其解析
  8. Android Studio安装以及解决连不上Android设备真机

随机推荐

  1. Android 应用程序基础(Application Fundam
  2. Android 文档的阅读顺序![转]
  3. android:configChanges配置不当,应用被回
  4. Android遍历API (1) 动画篇——克隆动画A
  5. android init进程分析 基本流程
  6. Android 的缓存机制 Lrucache
  7. Android 高仿微信头像截取 打造不一样的
  8. 学习android心里旅程
  9. Android(安卓)仿携程活动列表边框布局
  10. 实现类似android:clipChildren="false"的