check Bluetooth Availability On Device - Android android.bluetooth

Android examples for android.bluetooth:Bluetooth

Description

check Bluetooth Availability On Device

Demo Code

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  w  w . ja  v  a2  s. c o  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) {
          Toast toast = Toast.makeText(context, "Turn on Bluetooth", Toast.LENGTH_LONG);
          toast.show();
        }
      }
    }
    return false;
  }

}

Related Tutorials