Bluetooth篇 开发实例之七 匹配&UUID

匹配和通信是两回事。

1.用过Android系统设置(Setting)的人都知道蓝牙搜索之后可以建立配对解除配对,但是这两项功能的函数没有在SDK中给出。但是可以通过反射来获取。

知道这两个API的宿主(BluetoothDevice):

/** 
 * 与设备配对 参考源码:platform/packages/apps/Settings.git 
 * /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java 
 */  
static public boolean createBond(Class btClass,BluetoothDevice btDevice) throws Exception {  
    Method createBondMethod = btClass.getMethod("createBond");  
    Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);  
    return returnValue.booleanValue();  
}  
  
/** 
 * 与设备解除配对 参考源码:platform/packages/apps/Settings.git 
 * /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java 
 */  
static public boolean removeBond(Class btClass,BluetoothDevice btDevice) throws Exception {  
    Method removeBondMethod = btClass.getMethod("removeBond");  
    Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);  
    return returnValue.booleanValue();  
}  

地址:http://www.xuebuyuan.com/1657242.html

2.UUID的问题,就是一个编码而已,如果是自己写的应用程序,就可以随便定义一下了,反正都是自己用的。百度"uuid产生器"生成一个就可以了。

如果是和已经有的产品链接,则就需要知道UUID了,就不能随便定义了。要查看一下UUID。

UUID参考:http://blog.csdn.net/wletv/article/details/8957612

android开发之蓝牙配对连接的方法:

参考:http://blog.csdn.net/jason0539/article/details/17782035

原文地址:https://www.cnblogs.com/H-BolinBlog/p/5378196.html