Purpose - Check if blue tooth is available or not - Android Phone

Android examples for Phone:Bluetooth

Description

Purpose - Check if blue tooth is available or not

Demo Code


import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;

public class Main{
    /**/* w ww .j a va2 s  .co  m*/
     * Purpose - Check if blue tooth is available or not
     * 
     * @param context Current Activity\Context from which this method is called
     * 
     * */
    public static boolean isBluetoothEnabled(Context context) {
        if (context == null || (!FeatureUtils.IsBluetoothPresent(context)))
            return false;
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
                .getDefaultAdapter();
        return mBluetoothAdapter.isEnabled();
    }
    /**
     * Purpose - Check if Bluetooth is present.
     * 
     * @param context Current Activity\Context from which this method is called
     * */
    public static boolean IsBluetoothPresent(Context context) {
        if (context == null)
            return false;
        PackageManager pm = context.getPackageManager();
        return (pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH));
    }
}

Related Tutorials