Example usage for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE

List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.

Prototype

String ACTION_REQUEST_ENABLE

To view the source code for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.

Click Source Link

Document

Activity Action: Show a system activity that allows the user to turn on Bluetooth.

Usage

From source file:org.hopestarter.wallet.ui.send.SendCoinsFragment.java

private void updateStateFrom(final PaymentIntent paymentIntent) {
    log.info("got {}", paymentIntent);

    this.paymentIntent = paymentIntent;

    validatedAddress = null;/*w w  w  . j ava2 s  .  c om*/
    directPaymentAck = null;

    // delay these actions until fragment is resumed
    handler.post(new Runnable() {
        @Override
        public void run() {
            if (paymentIntent.hasPaymentRequestUrl() && paymentIntent.isBluetoothPaymentRequestUrl()) {
                if (bluetoothAdapter.isEnabled())
                    requestPaymentRequest();
                else
                    // ask for permission to enable bluetooth
                    startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                            REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST);
            } else if (paymentIntent.hasPaymentRequestUrl() && paymentIntent.isHttpPaymentRequestUrl()
                    && !Constants.BUG_OPENSSL_HEARTBLEED) {
                requestPaymentRequest();
            } else {
                setState(State.INPUT);

                receivingAddressView.setText(null);
                amountCalculatorLink.setBtcAmount(paymentIntent.getAmount());

                if (paymentIntent.isBluetoothPaymentUrl())
                    directPaymentEnableView
                            .setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
                else if (paymentIntent.isHttpPaymentUrl())
                    directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED);

                requestFocusFirst();
                updateView();
                handler.post(dryrunRunnable);
            }
        }
    });
}

From source file:com.updetector.MainActivity.java

/** Make sure that Bluetooth is enabled */
public void checkBluetoothEnabled() {
    if (mBluetoothAdapter == null) {
        // Device does not support Bluetooth
        AlertDialog noBluetoothAlert = new AlertDialog.Builder(this).setTitle("Bluetooth not supported.")
                .setPositiveButton("Exit", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                    }//from ww  w  .ja va  2 s .c  o m
                }).setCancelable(true).create();
        noBluetoothAlert.show();
        writeToConsole(
                "This phone does not have Bluetooth capability. Bluetooth connection method will not work.");
    }
    if (!mBluetoothAdapter.isEnabled()) {
        Log.e(LOG_TAG, "bluetooth not enabled yet");
        /** Ask user to enable Bluetooth */
        AlertDialog enableBluetoothDialog = new AlertDialog.Builder(this)
                .setTitle("Please enable Bluetooth on your phone.").setCancelable(false)
                .setPositiveButton("Enable Bluetooth", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                                Constants.SENSOR_BLUETOOTH);
                    }
                }).setNegativeButton("Skip", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                    }
                }).create();
        enableBluetoothDialog.show();
    } else {
        //bluetooth is enabled (directed from onActivityResult())         
        SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
        String carBluetoothDeviceName = null;
        if (mPrefs.contains(Constants.BLUETOOTH_CAR_DEVICE_NAME)) {
            carBluetoothDeviceName = mPrefs.getString(Constants.BLUETOOTH_CAR_DEVICE_NAME, null);
        }
        Log.e(LOG_TAG, "bluetooth enabled " + carBluetoothDeviceName);

        if (carBluetoothDeviceName != null) {
            Intent intent = new Intent(MainActivity.this, BluetoothConnectionService.class);
            startService(intent);
        } else {//ask the user to select a car bluetooth device
            selectBluetoothDevice();
        }
    }
}

From source file:org.thecongers.mcluster.MainActivity.java

private void checkBTState() {
    // Check for Bluetooth support and then check to make sure it is turned on
    if (btAdapter == null) {
        Log.d(TAG, "Bluetooth not supported");
    } else {/* w ww.  j av  a2 s  .c o  m*/
        if (btAdapter.isEnabled()) {
            Log.d(TAG, "Bluetooth is on");
        } else {
            //Prompt user to turn on Bluetooth
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, 1);
        }
    }
}