carora3
carora3

Reputation: 466

Switching on and off Bluetooth

How can I switch on and off bluetooth directly without needing to have a pop up asking user consent. I tried btAdapter.enable() but this did not work for me.

Upvotes: 1

Views: 336

Answers (4)

Rizvan
Rizvan

Reputation: 717

 String status;
   if (bluetooth.isEnabled()) {
    String mydeviceaddress = bluetooth.getAddress();
    String mydevicename = bluetooth.getName();
     status = mydevicename + ” : ” + mydeviceaddress;
           }
          else
                  {
                         status = “Bluetooth is not Enabled.”;
                  }

      Toast.makeText(this, status, Toast.LENGTH_LONG).show();

Do on or off now ur wish :)

Upvotes: 1

carora3
carora3

Reputation: 466

It required android.permission.BLUETOOTH_ADMIN permission

Upvotes: 0

NikhilReddy
NikhilReddy

Reputation: 6954

  if (!mBluetoothAdapter.isEnabled()) {
    //do some thing here
  }else{
    //do some thing here
    }

Upvotes: 0

Katie G.
Katie G.

Reputation: 46

As far as I know, you'd need to add it to the permissions xml (AndroidManifest.xml) file to not have user intervention.

http://www.brighthub.com/mobile/google-android/articles/103281.aspx

Upvotes: 2

Related Questions