简体   繁体   中英

Programmatically dismiss Bluetooth system alert dialog?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM