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:com.mchp.android.PIC32_BTSK.PIC32_BTSK.java

@Override
public void onStart() {
    super.onStart();
    if (D)//from   w  w w. j av a  2s.c om
        Log.e(TAG, "++ ON START ++");

    // If BT is not on, request that it be enabled.
    // setupBTService() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        // Otherwise, setup the Bluetooth session
    } else {
        if (mBluetoothService == null)
            setupBTService();
    }
}

From source file:pl.mrwojtek.sensrec.app.RecordsActivity.java

private void requestEnableBluetooth() {
    Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivity(intent);
}

From source file:com.duinopeak.balanbot.BalanbotActivity.java

@Override
public void onStart() {
    super.onStart();
    if (D)//from   w w  w . j  ava 2s .c  om
        Log.d(TAG, "++ ON START ++");
    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (!mBluetoothAdapter.isEnabled()) {
        if (D)
            Log.d(TAG, "Request enable BT");
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    } else
        setupBTService(); // Otherwise, setup the chat session

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Create SharedPreferences instance
    String filterCoefficient = preferences.getString("filterCoefficient", null); // Read the stored value for filter coefficient
    if (filterCoefficient != null) {
        mSensorFusion.filter_coefficient = Float.parseFloat(filterCoefficient);
        mSensorFusion.tempFilter_coefficient = mSensorFusion.filter_coefficient;
    }
    // Read the previous back to spot value
    backToSpot = preferences.getBoolean("backToSpot", true); // Back to spot is true by default
    // Read the previous max angle
    maxAngle = preferences.getInt("maxAngle", 8); // Eight is the default value
    // Read the previous max turning value
    maxTurning = preferences.getInt("maxTurning", 20); // Twenty is the default value
}

From source file:com.googlecode.android_scripting.facade.BluetoothFacade.java

@Rpc(description = "Toggle Bluetooth on and off.", returns = "True if Bluetooth is enabled.")
public Boolean toggleBluetoothState(@RpcParameter(name = "enabled") @RpcOptional Boolean enabled,
        @RpcParameter(name = "prompt", description = "Prompt the user to confirm changing the Bluetooth state.") @RpcDefault("true") Boolean prompt) {
    if (enabled == null) {
        enabled = !checkBluetoothState();
    }//from   ww w  .j a  v a 2s  .c  o  m
    if (enabled) {
        if (prompt) {
            Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            // TODO(damonkohler): Use the result to determine if this was successful. At any rate, keep
            // using startActivityForResult in order to synchronize this call.
            mAndroidFacade.startActivityForResult(intent);
        } else {
            // TODO(damonkohler): Make this synchronous as well.
            mBluetoothAdapter.enable();
        }
    } else {
        // TODO(damonkohler): Add support for prompting on disable.
        // TODO(damonkohler): Make this synchronous as well.
        shutdown();
        mBluetoothAdapter.disable();
    }
    return enabled;
}

From source file:com.nbplus.vbroadlauncher.fragment.LoadIoTDevicesDialogFragmentStatus.java

private void handleIoTReuslt(int cmd, final IoTServiceStatus serviceStatus,
        final IoTResultCodes serviceStatusCode, Bundle b) {
    Log.d(TAG, "IoTServiceResponse onResult...serviceStatus = " + serviceStatus + ", statusCode = "
            + serviceStatusCode);/*from   w w  w.  ja  v  a 2 s  . c o  m*/
    switch (cmd) {
    case IoTServiceCommand.GET_DEVICE_LIST:
        if (serviceStatus == null || serviceStatusCode == null) {
            Log.e(TAG, "Unknown service status...");
            break;
        }

        if (!serviceStatus.equals(IoTServiceStatus.RUNNING)) {
            ((BaseActivity) getActivity()).dismissProgressDialog();

            if (serviceStatusCode.equals(IoTResultCodes.BLE_NOT_SUPPORTED)
                    || serviceStatusCode.equals(IoTResultCodes.BLUETOOTH_NOT_SUPPORTED)
                    || serviceStatusCode.equals(IoTResultCodes.BIND_SERVICE_FAILED)) {
                Log.d(TAG, ">> Can't use service :: " + serviceStatusCode);
                new AlertDialog.Builder(getActivity()).setMessage(R.string.error_bluetooth_not_supported)
                        //.setTitle(R.string.alert_network_title)
                        .setCancelable(true)
                        .setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Intent sendIntent = new Intent();
                                sendIntent.setAction(Constants.ACTION_IOT_DEVICE_LIST);
                                sendIntent.putExtra(Constants.EXTRA_IOT_DEVICE_CANCELED, true);
                                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(sendIntent);

                                dialog.dismiss();
                                dismissDialogFragment();
                            }
                        }).show();
                break;
            } else if (serviceStatusCode.equals(IoTResultCodes.BLUETOOTH_NOT_ENABLED)) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                getActivity().startActivityForResult(enableBtIntent,
                        Constants.START_ACTIVITY_REQUEST_ENABLE_BT);
            } else {
                new AlertDialog.Builder(getActivity()).setMessage(R.string.error_bluetooth_not_supported)
                        //.setTitle(R.string.alert_network_title)
                        .setCancelable(true)
                        .setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        }).show();
            }
        } else {
            if (serviceStatusCode.equals(IoTResultCodes.SUCCESS)) {
                handleDeviceList(b);
            }
        }
        break;
    default:
        Log.d(TAG, "Unknown command ");
    }
}

From source file:br.liveo.ndrawer.ui.activity.MainActivity.java

License:asdf

@Override
public void onResume() {
    super.onResume();

    MovementProfile.status = 0;//w w  w. jav  a  2s .co m

    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_READY));
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_GENERATING));
    LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
            new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));

    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEET_ENABLE_BT);
    } else {
        if (Build.VERSION.SDK_INT >= 21) {
            mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
            settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
        }
    }
}

From source file:com.lge.helloFriendsCamera.ConnectionActivity.java

/**
 * Ask permissions and start scan if all permissions are granted
 *//*from w w  w .java 2 s  .c  o  m*/
private void checkBleScanPermissionAndStartScan() {
    Log.d(TAG, "PERMISSION_REQUEST: BLUETOOTH AND ACCESS_FINE_LOCATION");
    int loc_permissionCheck = ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.ACCESS_FINE_LOCATION);

    //Enable wifi
    if (!mWifiManager.isWifiEnabled())
        mWifiManager.setWifiEnabled(true);

    //Enable bt
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!bluetoothAdapter.isEnabled()) {
        Log.d(TAG, "Request bluetooth enable");
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        return;
    }

    //Get permission (ACCESS_FINE_LOCATION)
    if (loc_permissionCheck != PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Request ACTION_FINE_LOCATION permission");
        ActivityCompat.requestPermissions((Activity) mContext,
                new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
        return;
    }

    startScanDevice();
}

From source file:com.example.slidingmenuexample.ui.NXTRemoteControl.java

@Override
protected void onStart() {
    super.onStart();

    if (!NO_BT) {
        if (!mBluetoothAdapter.isEnabled()) {
            startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_ENABLE_BT);
        } else {// w ww  .  ja va2s  . c o m
            if (mSavedState == NXTTalker.STATE_CONNECTED) {
                BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mDeviceAddress);
                mNXTTalker.connect(device);
            } else {
                if (mNewLaunch) {
                    mNewLaunch = false;
                    findBrick();
                }
            }
        }
    }
}

From source file:com.duy.pascal.interperter.libraries.android.connection.bluetooth.AndroidBluetoothLib.java

@SuppressWarnings("unused")
@PascalMethod(description = "Toggle Bluetooth on and off.", returns = "True if Bluetooth is enabled.")
public Boolean toggleBluetoothState(@PascalParameter(name = "enabled") @RpcOptional Boolean enabled,
        @PascalParameter(name = "prompt", description = "Prompt the user to confirm changing the Bluetooth state.") @RpcDefault("true") Boolean prompt) {
    if (enabled == null) {
        enabled = !checkBluetoothState();
    }// w w w.j a  v a  2 s  . c  o  m
    if (enabled) {
        if (prompt) {
            Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            // TODO(damonkohler): Use the result to determine if this was successful. At any rate, keep
            // using startActivityForResult in order to synchronize this call.
            mAndroidFacade.startActivityForResult(intent);
        } else {
            // TODO(damonkohler): Make this synchronous as well.
            mBluetoothAdapter.enable();
        }
    } else {
        // TODO(damonkohler): Add support for prompting on disable.
        // TODO(damonkohler): Make this synchronous as well.
        onFinalize();
        mBluetoothAdapter.disable();
    }
    return enabled;
}

From source file:com.github.vgoliveira.panificadora.MainActivity.java

@Override
public void onResume() {
    super.onResume();
    Log.d(TAG, "onResume");
    if (!mBtAdapter.isEnabled()) {
        Log.i(TAG, "onResume - BT not enabled yet");
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    }/*from w w  w . j  av a 2s  . c  om*/
}