Permanently remove discoverability check while turning ON/OFF BlueTooth on Android

44 views Asked by At

I'm developing an Android app that is thinked to run for long periods of time. At certain moments I need to communicate with some Blutooth devices (both 3.0 and BLE) so the idea is to switch ON the BlueTooth when I need and then turning it OFF for the rest of time.

My problem come when I turn the BT ON and an alert always pops us saying about the discoverability of my device, and I wish to remove this alert.

Searching around for a solution, I tried :

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivityForResult(discoverableIntent, GlobalConfiguration.REQUEST_DISCOVERABLE);

and

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();
}

both unsuccessfully, standing that after BT state switch from ON -> OFF -> ON, the dialog about the discoverability comes up again.

There's a way to remove this alert forever, also after an ON/OFF of the BlueTooth?!

Thanks in advance

0

There are 0 answers