android 蓝牙隐藏对话框 后台配对
来源:互联网 发布:麦克风淘宝购买 编辑:程序博客网 时间:2024/04/29 20:35
最近在做一个项目用到蓝牙,但是所有蓝牙的操作必须要后台进行,于是网上搜了下找到了方法。。首先需要下面3个方法,通过反射去操作
static public boolean createBond(Class btClass, BluetoothDevice btDevice)throws Exception {Method createBondMethod = btClass.getMethod("createBond");Log.i("life", "createBondMethod = " + createBondMethod.getName());Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);return returnValue.booleanValue();}static public boolean setPin(Class btClass, BluetoothDevice btDevice,String str) throws Exception {Boolean returnValue = null;try {Method removeBondMethod = btClass.getDeclaredMethod("setPin",new Class[] { byte[].class });returnValue = (Boolean) removeBondMethod.invoke(btDevice,new Object[] { str.getBytes() });Log.i("life", "returnValue = " + returnValue);} catch (SecurityException e) {// throw new RuntimeException(e.getMessage());e.printStackTrace();} catch (IllegalArgumentException e) {// throw new RuntimeException(e.getMessage());e.printStackTrace();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return returnValue;}// 取消用户输入static public boolean cancelPairingUserInput(Class btClass,BluetoothDevice device) throws Exception {Method createBondMethod = btClass.getMethod("cancelPairingUserInput");// cancelBondProcess()Boolean returnValue = (Boolean) createBondMethod.invoke(device);Log.i("life", "cancelPairingUserInputreturnValue = " + returnValue);return returnValue.booleanValue();}
然后监听蓝牙配对的广播 匹配“android.bluetooth.device.action.PAIRING_REQUEST”这个action
然后分辨调用上面的setPin(mDevice.getClass(), mDevice, "1234"); // 手机和蓝牙采集器配对 createBond(mDevice.getClass(), mDevice); cancelPairingUserInput(mDevice.getClass(), mDevice);
其中上面的mDevice是你要去连接的那个蓝牙的对象 , 1234为配对的pin码
- android 蓝牙隐藏对话框 后台配对
- android 蓝牙配对
- android蓝牙自动配对
- Android蓝牙配对
- Android 蓝牙自动配对
- android 蓝牙自动配对问题
- android 取消蓝牙配对框 实现自动配对
- android 取消蓝牙配对框 实现自动配对
- Android 取消蓝牙配对框 实现自动配对
- android 蓝牙Bluetooth建立配对和解除配对
- android 取消蓝牙配对框 实现自动配对
- android 取消蓝牙配对框 实现自动配对
- 蓝牙配对
- 蓝牙配对
- android 实现蓝牙自动配对连接
- android蓝牙主动发起配对实例
- android 蓝牙搜索、配对连接通信总结
- Android蓝牙设备的配对,连接,搜索
- lwip源码分析1------综述及设备驱动层
- “DllRegisterServer的调用失败”问题解决办法
- win 8 store app 易网新闻阅读器 隐私声明
- javascript俄罗斯方块【附带源码】
- 简易通讯录(用链表完成)
- android 蓝牙隐藏对话框 后台配对
- iOS -- 开发技巧(二)
- android listview滑动底色变黑
- 万年历系统
- mysql基础操作
- UNA 工具概览(四)——Reach指数示例
- 展讯充电原理解析
- linux gdb 跟踪代码错行问题的解决
- 数字电视中TS包解码函数