Enable the bluetooth adapter. - Android Bluetooth

Android examples for Bluetooth:Turn On bluetooth

Description

Enable the bluetooth adapter.

Demo Code


//package com.java2s;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;

import android.content.Intent;

public class Main {
    /**//from www.  j ava 2s . c  om
     * Enable the bluetooth adapter.
     */
    public static void bluetoothEnable(Activity activity,
            boolean discoverable, int reqCode) {
        if (discoverable) {
            Intent discoverableIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableIntent.putExtra(
                    BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
            activity.startActivityForResult(discoverableIntent, reqCode);
        } else {
            Intent bluetoothIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            activity.startActivityForResult(bluetoothIntent, reqCode);
        }
    }
}

Related Tutorials