I am able to turn on/off Bluetooth without any prompt using the following code. It requires BLUETOOTH
and BLUETOOTH_ADMIN
permissions.
b
Finally I have found a way to do this using reflection.
Method method;
try {
method = bluetoothAdapter.getClass().getMethod("setScanMode", int.class, int.class);
method.invoke(bluetoothAdapter,BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,120);
Log.e("invoke","method invoke successfully");
}
catch (Exception e){
e.printStackTrace();
}
Warning: Above method is trying to invoke hidden method. So in future maybe it will not work.