关于蓝牙BLE开发中要做掉的东西——除了设备和客户端外的蓝牙匹配对话框,notification 蓝牙匹配的通知栏
来源:互联网 发布:数据采集网络兼职 编辑:程序博客网 时间:2024/04/26 01:36
1、一般情况下,我们在做蓝牙BLE的时候,是不需要匹配的,应该直接取连接,这一步,不需要刻意的去做自动匹配,我认为没有那个必要,因为他在不匹配的
情况下,一样可以连接,并且进行数据的交互,假设一定要做自动匹配的话,在BluetoothDevice 这个类中有隐藏的方法
/** @hide */ //取消用户输入
public boolean cancelPairingUserInput() {
if (sService== null) {
Log.e(TAG, "BT not enabled. Cannot create pairing user input");
return false;
}
try {
return sService.cancelBondProcess(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
和
/**
* Cancel an in-progress bonding request started with {@link #createBond}.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
*
* @return true on success, false on error
* @hide
*/。取消用户配对
public boolean cancelBondProcess() {
if (sService== null) {
Log.e(TAG, "BT not enabled. Cannot cancel Remote Device bond");
return false;
}
try {
Log.i(TAG, "cancelBondProcess() for device " + getAddress() +
" called by pid: " + Process.myPid() +
" tid: " + Process.myTid());
return sService.cancelBondProcess(this);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
在加上
/**
* Set the pin during pairing when the pairing method is {@link #PAIRING_VARIANT_PIN}
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
*
* @return true pin has been set
* false for error
*/
pin 将要匹配的密码
public boolean setPin(byte[] pin) {
if (sService== null) {
Log.e(TAG, "BT not enabled. Cannot set Remote Device pin");
return false;
}
try {
return sService.setPin(this, true, pin.length, pin);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
/**
* Start the bonding (pairing) process with the remote device.
* <p>This is an asynchronous call, it will return immediately. Register
* for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
* the bonding process completes, and its result.
* <p>Android system services will handle the necessary user interactions
* to confirm and complete the bonding process.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
*
* @return false on immediate error, true if bonding will begin
*/。进行与device进行连接的方法
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean createBond() {
if (sService== null) {
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
return false;
}
try {
Log.i(TAG, "createBond() for device " + getAddress() +
" called by pid: " + Process.myPid() +
" tid: " + Process.myTid());
return sService.createBond(this,TRANSPORT_AUTO);
} catch (RemoteException e) {Log.e(TAG, "", e);}
return false;
}
在定义广播,在广播中(android.bluetooth.device.action.PAIRING_REQUEST
)监听到此广播时,进行上述的与用户匹配,输入密码,取消用户输入久OK了当然上面的除了没有被隐藏的方法外其他都要用反射得到
2、有的需求中是这样的,加入你的设备是BLE,但是不是向蓝牙耳机那种单片机的设备,而是有可见屏幕给用户展示信息的设备,你完全可以去
用上面的方法进行去掉匹配对话框,但是它还会有关于系统的Notification在通知栏进行显示,此时,你要做的是拦截系统的广播,当然要在你做完相应的操作后,
具体拦截的方法将在我的另一篇文章 《关于拦截系统广播的那些坑中》
感谢博客园天边的星星的博客给我启示http://www.cnblogs.com/jason-star/archive/2012/09/10/2678368.html
- 关于蓝牙BLE开发中要做掉的东西——除了设备和客户端外的蓝牙匹配对话框,notification 蓝牙匹配的通知栏
- 医疗设备BLE蓝牙开发的总结。
- 扫描已匹配的蓝牙设备
- MacBook 蓝牙键盘的匹配
- Ble蓝牙的使用手册
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- android蓝牙开发 蓝牙设备的查找和连接
- 基于蓝牙BLE的智能设备开发(一)
- Android开发蓝牙与ble设备的通讯
- Android经典蓝牙和Ble蓝牙的对比
- Android BLE低功耗蓝牙开发(下) BLE客户端(中央设备)与GATT服务的通讯
- 洛谷 P1019 单词接龙
- Linux进程全解12——lIPC机制之管道,SystemV IPC介绍
- (转)python requests 高级用法 -- 包括SSL 证书错误的解决方案
- mysql 参数类型为map的用法
- hdu1203 I NEED A OFFER! 01背包
- 关于蓝牙BLE开发中要做掉的东西——除了设备和客户端外的蓝牙匹配对话框,notification 蓝牙匹配的通知栏
- 简洁的JS代码--几点建议-积累ing
- 最大黑区域-DFS
- MQTT 协议解析,java使用
- Python语法31[module/package+import]
- myeclipse安装js代码提示插件Spket
- poj2421(kruskal)(水题)
- 几点建议帮你写出简洁的JS代码
- WooCommerce——产品过滤器WooCommerce Products Filter