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:io.puzzlebox.bloom.ui.MakerFragment.java
@Override public void onResume() { super.onResume(); // updatePowerThresholds(); // updatePower(); if (!BloomSingleton.getInstance().mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, BloomSingleton.getInstance().REQUEST_ENABLE_BT); }//ww w. j a v a2 s. c o m getActivity().registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); // if (BloomSingleton.getInstance().connState) // setButtonText(R.id.connectBloom, "Disconnect Bloom"); // updateSessionTime(); LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(mPacketReceiver, new IntentFilter("io.puzzlebox.jigsaw.protocol.thinkgear.packet")); }
From source file:io.puzzlebox.bloom.ui.BloomFragment.java
@Override public void onResume() { super.onResume(); updatePowerThresholds();//from w w w . j a va 2s . c om updatePower(); if (!BloomSingleton.getInstance().mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, BloomSingleton.getInstance().REQUEST_ENABLE_BT); } getActivity().registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); Intent gattServiceIntent = new Intent(getActivity(), RBLService.class); getActivity().bindService(gattServiceIntent, mServiceConnection, getActivity().BIND_AUTO_CREATE); // if (BloomSingleton.getInstance().connState) // setButtonText(R.id.connectBloom, "Disconnect Bloom"); // updateSessionTime(); LocalBroadcastManager.getInstance(getActivity().getApplicationContext()).registerReceiver(mPacketReceiver, new IntentFilter("io.puzzlebox.jigsaw.protocol.thinkgear.packet")); }
From source file:com.example.RITW.Ble.BleProfileServiceReadyActivity.java
protected void showBLEDialog() { final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); }
From source file:com.teeptrak.controller.MainActivity.java
/************************************************************************************************/ // Handler Disconnect & Connect button public void onConnectBtnClicked(final View v) { if (!mBtAdapter.isEnabled()) { Log.i(TAG, "onClick - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else {//from w w w .ja v a 2s . co m if (mConnectBtn.getText().equals("Connect")) { //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); } else { //Disconnect button pressed if (mBtDevice != null) { mUartService.disconnect(); } } } }
From source file:com.kjsaw.alcosys.ibacapp.IBAC.java
private void InitializeAllServices() { if (_isConfiguringPhone) { return;//from ww w . ja va2 s. c om } if (!_bluetoothAdapter.isEnabled()) { // bluetooth is not enabled so wait until its enabled...then call this method again _isConfiguringPhone = true; Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { _iBACservice._messageProcessor.RegisterStateListener(this); if (_iBACservice.getState() == 0 && _bluetoothAdapter.isEnabled()) { final Intent serverIntent = new Intent(this, BluetoothIBACDiscovery.class); //BluetoothIBACDiscoveryLTE _btDiscovery = new Runnable() { public void run() { startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); } }; _handler.postDelayed(_btDiscovery, 1500); // 3000 // change to the blue logo ImageView mAlcoLogo = (ImageView) findViewById(R.id.mti); mAlcoLogo.setImageResource(R.drawable.alcogreenbg); _conversationArrayAdapter.clear(); _conversationArrayAdapterBottom.clear(); _conversationArrayAdapter.add(getResources().getString(R.string.turn_on_ibac)); } // Take an extra look on this if (_iBACservice != null) { if (_iBACservice.getState() == BluetoothIBACService.STATE_NONE) { _iBACservice.start(); } } } }
From source file:com.cesquerr.becky.app.MainActivity.java
private boolean manageBluetoothAvailability() { boolean isEnabled = true; // Check Bluetooth HW status int errorMessageId = 0; final int bleStatus = BleUtils.getBleStatus(getBaseContext()); switch (bleStatus) { case BleUtils.STATUS_BLE_NOT_AVAILABLE: errorMessageId = R.string.dialog_error_no_ble; isEnabled = false;//from w w w .java 2 s. c om break; case BleUtils.STATUS_BLUETOOTH_NOT_AVAILABLE: { errorMessageId = R.string.dialog_error_no_bluetooth; isEnabled = false; // it was already off break; } case BleUtils.STATUS_BLUETOOTH_DISABLED: { isEnabled = false; // it was already off // if no enabled, launch settings dialog to enable it (user should always be prompted before automatically enabling bluetooth) Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, kActivityRequestCode_EnableBluetooth); // execution will continue at onActivityResult() break; } } if (errorMessageId != 0) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog dialog = builder.setMessage(errorMessageId).setPositiveButton(android.R.string.ok, null) .show(); DialogUtils.keepDialogOnOrientationChanges(dialog); } return isEnabled; }
From source file:de.frank_durr.ble_v_monitor.MainActivity.java
/** * Query the GATT server for current voltage data. */// w ww . j ava2 s.c o m synchronized private void bleRetrieveCurrentVoltage() { if (activeBluetoothTask != BluetoothTasks.getVoltage) { // Task cancelled return; } // Check whether a BLE device has already been selected. If not, select it first. if (bluetoothDevice == null) { // No device selected so far -> let user select one 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. 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. characteristic = gattService.getCharacteristic(currentVoltageCharacteristicUUID); 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. if (!gatt.readCharacteristic(characteristic)) { // Cannot read characteristic value toast(R.string.err_bluetooth_read); finishTask(); return; } // Data is received and processed in GATT callback. Wait for GATT callback. }
From source file:com.adafruit.bluefruit.le.connect.app.MainActivity.java
private boolean manageBluetoothAvailability() { boolean isEnabled = true; // Check Bluetooth HW status int errorMessageId = 0; final int bleStatus = BleUtils.getBleStatus(getBaseContext()); switch (bleStatus) { case BleUtils.STATUS_BLE_NOT_AVAILABLE: errorMessageId = R.string.dialog_error_no_ble; isEnabled = false;/*from w w w . j a v a 2 s. c o m*/ break; case BleUtils.STATUS_BLUETOOTH_NOT_AVAILABLE: { errorMessageId = R.string.dialog_error_no_bluetooth; isEnabled = false; // it was already off break; } case BleUtils.STATUS_BLUETOOTH_DISABLED: { isEnabled = false; // it was already off // if no enabled, launch settings dialog to enable it (user should always be prompted before automatically enabling bluetooth) Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, kActivityRequestCode_EnableBluetooth); // execution will continue at onActivityResult() break; } } if (errorMessageId > 0) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog dialog = builder.setMessage(errorMessageId).setPositiveButton(android.R.string.ok, null) .show(); DialogUtils.keepDialogOnOrientationChanges(dialog); } return isEnabled; }
From source file:edu.stanford.mobisocial.dungbeetle.NearbyActivity.java
private void findBluetooth() { if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { Intent bt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(bt, RESULT_BT_ENABLE); return;//from w w w . j ava 2 s . co m } // Create a BroadcastReceiver for ACTION_FOUND final IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); final BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { new Thread() { public void run() { BluetoothBeacon.OnDiscovered discovered = new BluetoothBeacon.OnDiscovered() { @Override public void onDiscovered(final byte[] data) { runOnUiThread(new Runnable() { @Override public void run() { try { JSONObject obj = new JSONObject(new String(data)); mNearbyList.add( new NearbyItem(NearbyItem.Type.FEED, obj.getString("name"), Uri.parse(obj.getString("dynuri")), null)); mAdapter.notifyDataSetChanged(); } catch (JSONException e) { Log.e(TAG, "Error getting group info over bluetooth", e); } } }); } }; // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothBeacon.discover(NearbyActivity.this, device, discovered); }; }.start(); } if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { unregisterReceiver(this); } } }; registerReceiver(receiver, filter); // Don't forget to unregister during // onDestroy BluetoothAdapter.getDefaultAdapter().startDiscovery(); Toast.makeText(this, "Scanning Bluetooth...", 500).show(); }
From source file:com.example.pyrkesa.shwc.MainActivity.java
@Override protected void onStart() { super.onStart(); /** wearable part **/ mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).build(); if (!mGoogleApiClient.isConnected()) { mGoogleApiClient.connect();//www .j a v a 2s .c o m } /*******************/ // Check if device supports Bluetooth Low Energy. if (!beaconManager.hasBluetooth()) { Toast.makeText(this, "Device does not have Bluetooth Low Energy", Toast.LENGTH_LONG).show(); return; } // If Bluetooth is not enabled, let user enable it. if (!beaconManager.isBluetoothEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else { connectToService(); } }