我正在开发一个被认为可以长时间运行的 Android 应用程序。在某些时候,我需要与一些蓝牙设备(3.0 和 BLE)进行通信,所以我的想法是在需要时打开蓝牙,然后在其余时间将其关闭。
当我打开 BT 时,我的问题就出现了,并且总是弹出我们说我的设备可被发现的警报,我希望删除此警报。
四处寻找解决方案,我尝试了:
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivityForResult(discoverableIntent, GlobalConfiguration.REQUEST_DISCOVERABLE);
和
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Method method;
try {
method = bluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
method.invoke(bluetoothAdapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, 0);
}
catch(Exception e) {
e.printStackTrace();
}
都失败了,站在BT状态从ON -> OFF -> ON切换后,关于可发现性的对话框再次出现。
有一种方法可以永久删除此警报,在蓝牙开启/关闭之后也是如此?!
提前致谢