If Bluetooth is not enabled on the device, this method will fire an intent to open the system settings "enable Bluetooth" dialog. - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

If Bluetooth is not enabled on the device, this method will fire an intent to open the system settings "enable Bluetooth" dialog.

Demo Code


//package com.java2s;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;

public class Main {
    public static final int REQUEST_CODE_INTENT_ENABLE_BT = 0x1B071F31;

    /**//from  ww w .  j  a v a2s .  co m
     * If Bluetooth is not enabled on the device, this method will fire an intent
     * to open the system settings "enable Bluetooth" dialog.
     * @param fromActivity: calling activity.
     */
    public static void enableBluetooth(Activity fromActivity) {
        BluetoothAdapter bluetoothAdapter = BluetoothAdapter
                .getDefaultAdapter();
        if (!bluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            fromActivity.startActivityForResult(enableBtIntent,
                    REQUEST_CODE_INTENT_ENABLE_BT);
        }
    }
}

Related Tutorials