安卓蓝牙通过代码显示蓝牙可见时间设置
来源:互联网 发布:sql 修改字段为自增列 编辑:程序博客网 时间:2024/05/17 22:37
//会弹出一个确认框提醒用户
Intent discoverableIntent = newIntent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);startActivity(discoverableIntent);
//没有界面的调用
public void setDiscoverableTimeout(){ ClsUtils.setDiscoverableTimeout(adapter,0);//这里设置时间无效,只能通过延迟close LogUtil.e("setDiscoverableTimeout"); new Handler().postDelayed(new Runnable() { @Override public void run() { closeDiscoverableTimeout(); LogUtil.e("closeDiscoverableTimeout"); } }, 10000);//毫秒单位}
private void closeDiscoverableTimeout(){ closeDiscoverableTimeout(adapter);}public void setDiscoverableTimeout(BluetoothAdapter adapter,int timeout) { try { Method setDiscoverableTimeout = BluetoothAdapter.class.getMethod("setDiscoverableTimeout", int.class); setDiscoverableTimeout.setAccessible(true); Method setScanMode =BluetoothAdapter.class.getMethod("setScanMode", int.class,int.class); setScanMode.setAccessible(true); setDiscoverableTimeout.invoke(adapter, timeout); setScanMode.invoke(adapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,timeout); } catch (Exception e) { e.printStackTrace(); }}public void closeDiscoverableTimeout(BluetoothAdapter adapter) { try { Method setDiscoverableTimeout = BluetoothAdapter.class.getMethod("setDiscoverableTimeout", int.class); setDiscoverableTimeout.setAccessible(true); Method setScanMode =BluetoothAdapter.class.getMethod("setScanMode", int.class,int.class); setScanMode.setAccessible(true); setDiscoverableTimeout.invoke(adapter, 1); setScanMode.invoke(adapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE,1); } catch (Exception e) { e.printStackTrace(); }}
阅读全文
0 0
- 安卓蓝牙通过代码显示蓝牙可见时间设置
- Android通过反射机制实现后台设置蓝牙可见性
- 安卓5.0蓝牙低功耗 代码
- 关于android蓝牙开发中 蓝牙可见性设置
- android-设置蓝牙的可见性
- 关于android蓝牙可见性设置
- 安卓代码设置密码可见与不可见
- 安卓蓝牙开发
- 安卓蓝牙通信
- 安卓蓝牙总结
- 安卓蓝牙通信
- 安卓蓝牙通信
- 安卓蓝牙通信
- 安卓蓝牙通讯
- 安卓蓝牙通信
- 安卓蓝牙开发
- 安卓蓝牙流程
- 安卓蓝牙开发
- PHP6 文件操作
- 剑指offer——14.链表中倒数第k个结点
- rownum使用pk
- HDU6011-度度熊的01世界
- java 集合比较 排序
- 安卓蓝牙通过代码显示蓝牙可见时间设置
- hdu6109数据分割(并查集+set)
- 原生JS里的onbeforeunload与onunload事件
- 关于Google Chrome的跨域设置
- ubuntu中运行python脚本
- 二叉堆,堆排序,STL优先队列的底层实现,剑指offer数据流中的中位数
- PHP7 正则
- 爬取《战狼2》电影短评论,生成图云
- 爬虫实践(二)--掌阅书城