android - 如何在不通过蓝牙确认对话框的情况下使我的设备能够被附近的设备发现?
问题描述
我在 Android 中做了一个与蓝牙连接相关的应用程序,每次启用蓝牙时,它都会显示一个确认对话框,使您的设备无法在设备附近发现。
有什么方法可以在没有确认对话框的情况下使设备发现。
我用过这个:
Intent Intent= new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
Intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
解决方案
我发现这很有帮助:
try {
Method bluetoothDeviceVisibility;
bluetoothDeviceVisibility = bluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
bluetoothDeviceVisibility.invoke(bluetoothAdapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, 0);
} catch (Exception e) {
e.printStackTrace();
}
推荐阅读
- python - DataFrame 按具有字典值的列分组
- c++ - 如何减少 C++ 优先级队列的值?
- javascript - 为什么VSCode对函数参数的类型检查会忽略类型对象?
- sql-server - 批量插入(SQL 服务器)是否仅适用于外部文件?
- reactjs - 如果在更新 aad 令牌时发生错误,我该如何重定向到登录页面?
- latex - !包 inputenc 错误:Unicode 字符 ^^H (U+0008)
- r - 根据来自另一个向量的字符串匹配过滤 data.table
- node.js - 使用 GCP Speech To Text 的电子桌面应用程序 - 无法保持连接打开
- r - rtweet 搜索查询返回的推文比前几天少得多
- android-9.0-pie - Android:即使清除了整个浏览器历史记录,我如何确保不删除 Google 安全搜索设置?