check Bluetooth Availability On Device - Android Bluetooth

Android examples for Bluetooth:Bluetooth Device

Description

check Bluetooth Availability On Device

Demo Code


//package com.java2s;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class Main {
    public static Boolean checkBluetoothAvailabilityOnDevice() {
        return checkBluetoothAvailabilityOnDevice(null);
    }//w ww  .j a  va  2  s  .co  m

    public static Boolean checkBluetoothAvailabilityOnDevice(Context context) {

        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter == null) {
            Log.e("Fatal Error", "Bluetooth not support");
        } else {
            if (btAdapter.isEnabled()) {
                Log.d("checkBluetoothAvailabilityOnDevice",
                        "...Bluetooth ON...");
                return true;
            } else {
                //Prompt user to turn on Bluetooth
                if (context != null) {
                    Log.d("checkBluetoothAvailabilityOnDevice",
                            "User needs to turn on Bluetooth");
                    Toast toast = Toast.makeText(context,
                            "Turn on Bluetooth", Toast.LENGTH_LONG);
                    toast.show();
                }
            }
        }
        return false;
    }
}

Related Tutorials