How do we know which button is pressed on Turn On Bluetooth Dialog?

I am preparing an extension to work with Bluetooth. In that, i am using the following code to Turn On Bluetooth.

	if (!myBluetoothAdapter.isEnabled()) {
		Intent myIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
		activity.startActivityForResult(myIntent, 0);

Obviously, it shows a dialog box asking the user permission to ALLOW or DENY !

Now, the question is that: How do we know which button is pressed by the user ?

The code has to catch the user response: either ALLOW button is pressed or DENY button is pressed.

I am requesting the community help in this regard.

Thank you.

1 Like

Meybe this code can help you :

android.bluetooth.BluetoothAdapter bluetoothAdapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
boolean isEnabled = bluetoothAdapter.isEnabled();
if (_enable && !isEnabled) {
} else if(!_enable && isEnabled) {

Or Meybe this code can help you :
Bluetooth Codes.txt (2.7 KB)

Or you can see here :

Thank you very much for your response.
I will try the code and share the result.

You're welcome @Automate_MyProject