Java tutorial
//package com.java2s; //License from project: Apache License import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothManager; import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; public class Main { /** * Check if bluetooth function enabled * * @param context the context * @return true if bluetooth enabled */ public static boolean isBluetoothEnabled(@NonNull Context context) { BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); if (bluetoothManager == null) { return false; } final BluetoothAdapter bluetoothAdapter; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { bluetoothAdapter = bluetoothManager.getAdapter(); } else { bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); } if (bluetoothAdapter == null) { return false; } return bluetoothAdapter.isEnabled(); } }