is Bluetooth Open - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

is Bluetooth Open

Demo Code


//package com.java2s;

import android.bluetooth.BluetoothAdapter;

public class Main {

    public static boolean isBluetoothOpen() throws Exception {
        int bluetoothStateCode = getBluetoothState();
        return bluetoothStateCode == BluetoothAdapter.STATE_ON
                || bluetoothStateCode == BluetoothAdapter.STATE_TURNING_ON ? true
                : false;/*from   w ww . java  2s . co  m*/
    }

    public static int getBluetoothState() throws Exception {
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter
                .getDefaultAdapter();
        if (bluetoothAdapter == null) {
            throw new Exception("bluetooth device not found!");
        } else {
            return bluetoothAdapter.getState();
        }
    }
}

Related Tutorials