2

I would like to disable bluetooth after I am done with it as part of my cleanup activities. As explained in other questions and the android documentation, the BluetoothAdapter.disable() method disable bluetooth but the method documentation also states

Bluetooth should never be disabled without direct user consent. The disable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.

The obvious approach for user consent would be to make my own popup and ask for consent. Other than this, to keep the approach to enable and disable similiar,

Is there an intent action similiar to Bluetooth Enable ( ACTION_REQUEST_INTENT ) available to disable bluetooth?

  • Possible duplicate of [How to enable/disable bluetooth programmatically in android](http://stackoverflow.com/questions/3806536/how-to-enable-disable-bluetooth-programmatically-in-android) – verybadalloc Dec 29 '15 at 06:58
  • @verybadalloc - the question only talks about using the BluetoothAdapter.disable() method. I am looking for an intent action for this. – pranshuagarwal Dec 29 '15 at 07:09

2 Answers2

1

There is no intent that exists to achieve what you want. It has to be done through the BluetoothAdapter

verybadalloc
  • 5,768
  • 2
  • 33
  • 49
0

display this dialog onButton click to disable bluetooth

public void showDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Confirm");
    builder.setMessage("Are you sure?");

    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            //Disable bluetooth
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    
            if (mBluetoothAdapter.isEnabled()) {
                mBluetoothAdapter.disable(); 
            } 
        }

    });

    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
            dialog.dismiss();
        }
    });

    AlertDialog alert = builder.create();
    alert.show();
}
Ankush Bist
  • 1,862
  • 1
  • 15
  • 32
  • Thanks ankush! I am doing the same currently as well. Just hoped if I could delegate this to an android activity using an intent rather than doing it myself. Hence the question. – pranshuagarwal Dec 29 '15 at 07:44
  • no sir android, even i checked for that myself i think android does not provide that – Ankush Bist Dec 29 '15 at 08:04