init Bluetooth Device - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth On Off

Description

init Bluetooth Device

Demo Code

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;

public class Main{


    private static BluetoothAdapter mBluetoothAdapter;
    public static boolean initBluetooth() {
        boolean state = false;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (!mBluetoothAdapter.isEnabled()) {
            System.out.println("Bluetooth is Disable...");
            state = true;/*w  ww .ja  va2  s . co m*/
        } else if (mBluetoothAdapter.isEnabled()) {
            String address = mBluetoothAdapter.getAddress();
            String name = mBluetoothAdapter.getName();
            System.out.println(String.format(
                    "Bluetooth name: %s. Address: %s", name, address));
            state = false;
        }
        return state;
    }

}

Related Tutorials