enables/disables bluetooth. - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

enables/disables bluetooth.

Demo Code


//package com.java2s;

import android.bluetooth.BluetoothAdapter;

public class Main {
    /**/*  w ww .j  ava2s  .c  o m*/
     * enables/disables bluetooth. Will return true if the status was toggled, false if no change was made (due to adapter already being in requested state)
     *
     * @param enabled
     * @return
     */
    public static boolean setBluetoothEnabled(boolean enabled) {
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter
                .getDefaultAdapter();
        if (!enabled && bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.disable();
            return true;
        } else if (enabled && !bluetoothAdapter.isEnabled()) {
            bluetoothAdapter.enable();
            return true;
        }
        return false;
    }
}

Related Tutorials