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

1.检测连接状态:

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

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

  1. int flag = -1;
  2. if (a2dp == BluetoothProfile.STATE_CONNECTED) {
  3. flag = a2dp;
  4. } else if (headset == BluetoothProfile.STATE_CONNECTED) {
  5. flag = headset;
  6. } else if (health == BluetoothProfile.STATE_CONNECTED) {
  7. flag = health;
  8. }
  9. if (flag != -1) {
  10. bluetoothAdapter.getProfileProxy(MainActivity.this, new ServiceListener() {
  11. @Override
  12. public void onServiceDisconnected(int profile) {
  13. // TODO Auto-generated method stub
  14. }
  15. @Override
  16. public void onServiceConnected(int profile, BluetoothProfile proxy) {
  17. // TODO Auto-generated method stub
  18. List<BluetoothDevice> mDevices = proxy.getConnectedDevices();
  19. if (mDevices != null && mDevices.size() > 0) {
  20. for (BluetoothDevice device : mDevices) {
  21. Log.i("W", "device name: " + device.getName());
  22. }
  23. } else {
  24. Log.i("W", "mDevices is null");
  25. }
  26. }
  27. }, flag);
  28. }

android 获取蓝牙已连接设备的更多相关文章

  1. Android获取蓝牙地址

    最近做一个项目,发现Android6.0以上的版本获取的蓝牙地址始终为02:00:00:00, Google一下发现Android早就封掉了相关接口,于是想到反射的方式去获取Mac地址,在此记录一下 ...

  2. 【转】Android低功耗蓝牙应用开发获取的服务UUID

    原文网址:http://blog.csdn.net/zhangjs0322/article/details/39048939 Android低功耗蓝牙应用程序开始时获取到的蓝牙血压计所有服务的UUID ...

  3. Android - 传统蓝牙(蓝牙2.0)

    Android Bluetooth 源码基于 Android L [TOC] Reference BluetoothAdapter 首先调用静态方法getDefaultAdapter()获取蓝牙适配器 ...

  4. Android 开发 蓝牙开发

    前言 蓝牙开发其实分2个部分,一个是正常蓝牙功能的开发(比如Android蓝牙的互相连接.读取蓝牙列表.文件传输.蓝牙耳机等等).另外一个是BLE蓝牙开发(属于低功耗蓝牙设备,设备大多是血糖仪.蓝牙手 ...

  5. Android BLE蓝牙详细解读

    代码地址如下:http://www.demodashi.com/demo/15062.html 随着物联网时代的到来,越来越多的智能硬件设备开始流行起来,比如智能手环.心率检测仪.以及各式各样的智能家 ...

  6. Android 串口蓝牙通信开发Java版本

    Android串口BLE蓝牙通信Java版 0. 导语 Qt on Android 蓝牙通信开发 我们都知道,在物联网中,BLE蓝牙是通信设备的关键设备.在传统的物联网应用中,无线WIFI.蓝牙和Zi ...

  7. Android低功耗蓝牙(BLE)使用详解

    代码地址如下:http://www.demodashi.com/demo/13390.html 与普通蓝牙相比,低功耗蓝牙显著降低了能量消耗,允许Android应用程序与具有更严格电源要求的BLE设备 ...

  8. Android BLE 蓝牙编程(一)

    最近在研究这个,等我有时间来写吧! 终于在端午节给自己放个假,现在就来说说关于android蓝牙ble的 最近的学习成果吧!! 需要材料(写个简单教程吧--关于小米手环的哦!嘿嘿) Android 手 ...

  9. Android ble 蓝牙4.0 总结

    本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API level < 18,也是用不了蓝牙4.0的哦 ...

随机推荐

  1. jquery on event

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  2. codeforces 544 D Destroying Roads 【最短路】

    题意:给出n个点,m条边权为1的无向边,破坏最多的道路,使得从s1到t1,s2到t2的距离不超过d1,d2 因为最后s1,t1是连通的,且要破坏掉最多的道路,那么就是求s1到t1之间的最短路 用bfs ...

  3. Rendering and compositing out of process iframes

    For Developers‎ > ‎Design Documents‎ > ‎Out-of-Process iframes (OOPIFs)‎ > ‎ Rendering and ...

  4. WSGI和CGI

    https://www.zhihu.com/question/19998865 https://segmentfault.com/a/1190000003069785

  5. iOS开发——剪切板

    剪切板的调用是很简单的,常用的就这两个,不管文字或是图片的粘贴复制,对剪切板的操作就是基于下面两个属性的: [UIPasteboard generalPasteboard].string [UIPas ...

  6. 移动端viewport解惑

    我们在做移动端webapp的时候需要设置这么一段: <meta name="viewport" content="width=device-width, initi ...

  7. parted---磁盘分区

    parted命令是由GNU组织开发的一款功能强大的磁盘分区和分区大小调整工具,与fdisk不同,它支持调整分区的大小.作为一种设计用于Linux的工具,它没有构建成处理与fdisk关联的多种分区类型, ...

  8. JavaScript 回车键绑定登录 事件 常用键位码(keyCode)

    1.回车键绑定登录事件 $(document).keydown(function (e) { if ((e.keyCode || e.which) == 13) { //document.queryS ...

  9. python中的future,你见过可以使用未来版本模块的语言吗?

    import xxx from yy.xxx import xx from yy.xxx import xx as x python最常见的导包导模块语句 yy为包名,包就是文件夹,模块就是xxx.p ...

  10. 学习笔记 Java_静态_继承 2014.7.12

    一.静态 1.构造函数:       特点:       1. 函数名和类名同样.       2. 不用定义返回值类型(和void不是一回事,而构造函数是根本不用定义返回值类型).       3. ...