简体   繁体   English

以编程方式关闭蓝牙系统警报对话框?

[英]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?当用户通过通知栏启用蓝牙时,我能否以某种方式关闭此对话框或提醒 Android 完成活动并返回结果(在这种情况下是成功的)?

No it is not possible to programmatically dismiss the Bluetooth system alert dialog you see on Android 9+不,不可能以编程方式关闭您在 Android 9+ 上看到的蓝牙系统警报对话框

However, you can avoid the system alert dialog by enabling Bluetooth programatically, at least on Android 8 and less:但是,您可以通过以编程方式启用蓝牙来避免系统警报对话框,至少在 Android 8 及更低版本上:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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