Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Enable/Disable Bluetooth

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 47
    Comment on it

    How to on-off the bluetooth progamatically in android:-

    Here, we will use the class "BluetoothAdapter" , which allow us to all bluetooth interaction and perform its tasks.

    Firstly , we have to set permission in manifest to access device bluetooth.

     <uses-permission android:name="android.permission.BLUETOOTH"/>
     <uses-permission android:name="android.permission.BLUETOOTH&#95;ADMIN"/>
    

    Now we have to check whether bluetooth is on or off.

     BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
     boolean isBluetoothOn = bluetoothAdapter.isEnabled();
    

    A the end you can on or off the bluetooth as per your requirement.

    if (!isBluetoothOn) {
            bluetoothAdapter.enable(); 
        }
        else if(isBluetoothOn) {
            bluetoothAdapter.disable();
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: