Programmatically dismiss Bluetooth system alert dialog?

Viewed 370

My app detects whether Bluetooth is disabled and triggers a system alert dialog (to enable Bluetooth) through:

startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), 1711);

It is, however, also possible to enable Bluetooth through the notification bar and when Bluetooth is enabled there the system alert dialog is still shown.

Can I somehow dismiss this dialog or remind Android to finish the activity and return the result (which is successful in this case) when the user enables Bluetooth through the notification bar?

1 Answers

No it is not possible to programmatically dismiss the Bluetooth system alert dialog you see on Android 9+

However, you can avoid the system alert dialog by enabling Bluetooth programatically, at least on Android 8 and less:

final BluetoothAdapter ba = BluetoothManagerCompat.getAdapter(yourActivity);
ba.enable();
Related