List of usage examples for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE
String ACTION_REQUEST_ENABLE
To view the source code for android.bluetooth BluetoothAdapter ACTION_REQUEST_ENABLE.
Click Source Link
From source file:com.elitise.appv2.Peripheral.java
private void ensureBleFeaturesAvailable() { if (mBluetoothAdapter == null) { Toast.makeText(this, R.string.bluetoothNotSupported, Toast.LENGTH_LONG).show(); Log.e(TAG, "Bluetooth not supported"); finish();/*w w w .j ava2 s .co m*/ } else if (!mBluetoothAdapter.isEnabled()) { // Make sure bluetooth is enabled. Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }
From source file:de.frank_durr.ble_v_monitor.MainActivity.java
/** * Query the GATT server for a voltage history. * * @param historyType the history to be retrieved from the GATT server *///w ww.j ava2s .c o m synchronized private void bleRetrieveHistory(HistoryTypes historyType) { switch (historyType) { case historyMinutely: if (activeBluetoothTask != BluetoothTasks.getMinutelyHistory) { return; } break; case historyHourly: if (activeBluetoothTask != BluetoothTasks.getHourlyHistory) { return; } break; case historyDaily: if (activeBluetoothTask != BluetoothTasks.getDailyHistory) { return; } break; } // Check whether a BLE device has already been selected. If not, select device first. if (bluetoothDevice == null) { // No device selected so far -> let user select device now selectDevice(); return; // Wait for activity result } // BLE device has been selected. if (!bluetoothAdapter.isEnabled()) { // First, turn on Bluetooth Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, REQUEST_ENABLE_BT); return; // Wait for activity result } // BLE device has been selected. BLE is turned on. // From here on, we show a progress dialog ... retrieving hundreds of // BLE indications (stop&wait protocol) can take longer. if (progressDialog == null) { String dialogTitle = getString(R.string.waiting); String dialogMessage = getString(R.string.download_in_progress); String cancel = getString(R.string.cancel); progressDialog = new ProgressDialog(this); progressDialog.setTitle(dialogTitle); progressDialog.setMessage(dialogMessage); progressDialog.setCancelable(true); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMax(MAX_HISTORY_SIZE); progressDialog.setProgress(0); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finishTask(); } }); progressDialog.show(); } if (gatt == null) { bluetoothDevice.connectGatt(this, false, gattHandler); return; // Wait for callback } // BLE device has been selected. BLE is turned on. We are connected to GATT server. if (!gattServicesDiscovered) { if (!gatt.discoverServices()) { // Cannot start discovery toast(R.string.err_bluetooth_discovery); finishTask(); return; } return; // Wait for GATT callback } // BLE device has been selected. BLE is turned on. We are connected to GATT server. // GATT services have been discovered. gattService = gatt.getService(gattServiceUUID); if (gattService == null) { // Required service not offered by device toast(R.string.err_bluetooth_service); finishTask(); return; } // BLE device has been selected. BLE is turned on. We are connected to GATT server. // GATT services have been discovered. Service is ready. switch (historyType) { case historyMinutely: characteristic = gattService.getCharacteristic(minutelyHistoryCharacteristicUUID); break; case historyHourly: characteristic = gattService.getCharacteristic(hourlyHistoryCharacteristicUUID); break; case historyDaily: characteristic = gattService.getCharacteristic(dailyHistoryCharacteristicUUID); break; } if (characteristic == null) { // Required characteristic is not available. toast(R.string.err_bluetooth_characteristic); finishTask(); return; } // BLE device has been selected. BLE is turned on. We are connected to GATT server. // GATT services have been discovered. Service is ready. Characteristic is available. // History values are returned as indications. -> subscribe for notifications. if (!gatt.setCharacteristicNotification(characteristic, true)) { toast(R.string.err_bluetooth_notification); finishTask(); return; } BluetoothGattDescriptor descriptor = characteristic.getDescriptor(clientCharacteristicConfigurationUUID); if (descriptor == null) { toast(R.string.err_bluetooth_notification); finishTask(); return; } if (!descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)) { toast(R.string.err_bluetooth_notification); finishTask(); return; } if (!gatt.writeDescriptor(descriptor)) { toast(R.string.err_bluetooth_notification); finishTask(); return; } // Data is received and processed in GATT callback. Wait for GATT callback. }
From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java
public void checkBluetoothStatus() { /**//w w w. j av a2 s.c o m * Ensures Blue tooth is enabled on the device. If Blue tooth is not * currently enabled, fire an intent to display a dialog asking the user * to grant permission to enable it. */ if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }
From source file:com.nest5.businessClient.Initialactivity.java
@Override protected void onStart() { super.onStart(); FlurryAgent.onStartSession(this, "J63XVCZCXV4NN4P2SQZT"); //mReader.start(); // If BT is not on, request that it be enabled. BT // setupChat() will then be called during onActivityRe//sultsetupChat() onActivityResult //recoverCookingOrders();//recover every single order that was on hold before the application was closed RecoverThread recoverBackUp = new RecoverThread(this); recoverBackUp.run();/*from w w w. j a va 2 s . c om*/ isPausing = false; mHandler.postDelayed(contador, 60 * 1000); backUpOrdersHandler.postDelayed(constantBackUp, 1000 * 30); updateRegistrables(); //update all elements than can be sold (ingredients, products, combos) try { if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); // Otherwise, setup the serial session } else { if (mChatService == null) setupChat(); //if (mSerialService == null) setupChat(); } } catch (Exception e) { e.printStackTrace(); } SharedPreferences prefs = Util.getSharedPreferences(mContext); String deviceId = prefs.getString(Setup.DEVICE_REGISTERED_ID, "null"); String compid = prefs.getString(Setup.COMPANY_ID, "0"); String jString = "{device_id:" + deviceId + ",company:" + compid + "}"; BugSenseHandler.setUserIdentifier(jString); }
From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java
@Override public synchronized void onResume() { super.onResume(); if (!mEnablingBT) { if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) { mEnablingBT = true;/*from ww w. j a v a 2s . c o m*/ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.alert_dialog_turn_on_bt).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.alert_dialog_warning_title).setCancelable(false) .setPositiveButton(R.string.alert_dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { mEnablingBT = true; dialog.dismiss(); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } }).setNegativeButton(R.string.alert_dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { finishDialogNoBluetooth(); } }); AlertDialog alert = builder.create(); alert.show(); } if (mSerialService != null) { if (mSerialService.getState() == BluetoothSerialService.STATE_NONE) { mSerialService.start(); } } String tmp_logfile = log_file; boolean append_state = false; if (mBluetoothAdapter != null) { if (initapp == false) { if (profile == 0) { if (initialized == true) { readPrefs(); } } else { if (initialized == true) { readPrefs(); } } } } if (log_file.equals(tmp_logfile)) { append_state = true; } if (worker != null && writelog == true) { worker.getFile(append_state); worker.setPause(false); } if (changed_prefs == true) { changed_prefs = false; readPrefs(); } } }
From source file:com.rimbit.android_wallet.ui.SendCoinsFragment.java
private void updateStateFrom(final @Nonnull PaymentIntent paymentIntent) { log.info("got {}", paymentIntent); this.paymentIntent = paymentIntent; directPaymentAck = null;//w w w .ja v a2 s. c om // delay these actions until fragment is resumed handler.post(new Runnable() { @Override public void run() { if (state == State.INPUT) { amountCalculatorLink.setRBTAmount(paymentIntent.getAmount()); if (paymentIntent.isBluetoothPaymentUrl()) directPaymentEnableView .setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled()); else if (paymentIntent.isHttpPaymentUrl()) directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED); requestFocusFirst(); updateView(); } if (paymentIntent.hasPaymentRequestUrl()) { if (paymentIntent.isBluetoothPaymentRequestUrl() && !Constants.BUG_OPENSSL_HEARTBLEED) { if (bluetoothAdapter.isEnabled()) requestPaymentRequest(paymentIntent.paymentRequestUrl); else // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST); } else if (paymentIntent.isHttpPaymentRequestUrl()) { requestPaymentRequest(paymentIntent.paymentRequestUrl); } } } }); }
From source file:com.bushstar.htmlcoin_android_wallet.ui.SendCoinsFragment.java
private void updateStateFrom(final @Nonnull PaymentIntent paymentIntent) { log.info("got {}", paymentIntent); this.paymentIntent = paymentIntent; directPaymentAck = null;/*from w w w .j av a2s . c o m*/ // delay these actions until fragment is resumed handler.post(new Runnable() { @Override public void run() { if (state == State.INPUT) { amountCalculatorLink.setHTML5Amount(paymentIntent.getAmount()); if (paymentIntent.isBluetoothPaymentUrl()) directPaymentEnableView .setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled()); else if (paymentIntent.isHttpPaymentUrl()) directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED); requestFocusFirst(); updateView(); } if (paymentIntent.hasPaymentRequestUrl()) { if (paymentIntent.isBluetoothPaymentRequestUrl() && !Constants.BUG_OPENSSL_HEARTBLEED) { if (bluetoothAdapter.isEnabled()) requestPaymentRequest(paymentIntent.paymentRequestUrl); else // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST); } else if (paymentIntent.isHttpPaymentRequestUrl()) { requestPaymentRequest(paymentIntent.paymentRequestUrl); } } } }); }
From source file:com.matthewmitchell.nubits_android_wallet.ui.SendCoinsFragment.java
private void updateStateFrom(final @Nonnull PaymentIntent paymentIntent) { log.info("got {}", paymentIntent); this.paymentIntent = paymentIntent; directPaymentAck = null;/* ww w . ja v a2 s .c o m*/ // delay these actions until fragment is resumed handler.post(new Runnable() { @Override public void run() { if (state == State.INPUT) { amountCalculatorLink.setNBTAmount(paymentIntent.getAmount()); if (paymentIntent.isBluetoothPaymentUrl()) directPaymentEnableView .setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled()); else if (paymentIntent.isHttpPaymentUrl()) directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED); requestFocusFirst(); updateView(); } if (paymentIntent.hasPaymentRequestUrl()) { if (paymentIntent.isBluetoothPaymentRequestUrl() && !Constants.BUG_OPENSSL_HEARTBLEED) { if (bluetoothAdapter.isEnabled()) requestPaymentRequest(paymentIntent.paymentRequestUrl); else // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST); } else if (paymentIntent.isHttpPaymentRequestUrl()) { requestPaymentRequest(paymentIntent.paymentRequestUrl); } } } }); }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.SendCoinsFragment.java
private void updateStateFrom(final @Nonnull PaymentIntent paymentIntent) { log.info("got {}", paymentIntent); this.paymentIntent = paymentIntent; directPaymentAck = null;//from w w w . j av a 2 s. com // delay these actions until fragment is resumed handler.post(new Runnable() { @Override public void run() { if (state == State.INPUT) { amountCalculatorLink.setPPCAmount(paymentIntent.getAmount()); if (paymentIntent.isBluetoothPaymentUrl()) directPaymentEnableView .setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled()); else if (paymentIntent.isHttpPaymentUrl()) directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED); requestFocusFirst(); updateView(); } if (paymentIntent.hasPaymentRequestUrl()) { if (paymentIntent.isBluetoothPaymentRequestUrl() && !Constants.BUG_OPENSSL_HEARTBLEED) { if (bluetoothAdapter.isEnabled()) requestPaymentRequest(paymentIntent.paymentRequestUrl); else // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST); } else if (paymentIntent.isHttpPaymentRequestUrl()) { requestPaymentRequest(paymentIntent.paymentRequestUrl); } } } }); }
From source file:com.hamradiocoin.wallet.ui.send.SendCoinsFragment.java
private void updateStateFrom(final @Nonnull PaymentIntent paymentIntent) { log.info("got {}", paymentIntent); this.paymentIntent = paymentIntent; directPaymentAck = null;// w w w .ja va 2s . c o m // delay these actions until fragment is resumed handler.post(new Runnable() { @Override public void run() { if (state == State.INPUT) { 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(); } if (paymentIntent.hasPaymentRequestUrl()) { if (paymentIntent.isBluetoothPaymentRequestUrl() && !Constants.BUG_OPENSSL_HEARTBLEED) { if (bluetoothAdapter.isEnabled()) requestPaymentRequest(paymentIntent.paymentRequestUrl); else // ask for permission to enable bluetooth startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST); } else if (paymentIntent.isHttpPaymentRequestUrl()) { requestPaymentRequest(paymentIntent.paymentRequestUrl); } } } }); }