List of usage examples for android.bluetooth BluetoothDevice BOND_NONE
int BOND_NONE
To view the source code for android.bluetooth BluetoothDevice BOND_NONE.
Click Source Link
From source file:Main.java
public static String formatBondState(int bondState) { switch (bondState) { case BluetoothDevice.BOND_NONE: return "Not Bonded"; case BluetoothDevice.BOND_BONDING: return "Bonding"; case BluetoothDevice.BOND_BONDED: return "Bonded"; default://w w w . j ava 2 s . c om return "Unknown"; } }
From source file:com.bluetooth.mwoolley.microbitbledemo.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setButtonText();//www . j a va 2 s .com getSupportActionBar().setTitle(R.string.screen_title_main); showMsg(Utility.htmlColorGreen("Ready")); Settings.getInstance().restore(this); ble_device_list_adapter = new ListAdapter(); ListView listView = (ListView) this.findViewById(R.id.deviceList); listView.setAdapter(ble_device_list_adapter); registerReceiver(broadcastReceiver, new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)); ble_scanner = BleScannerFactory.getBleScanner(this.getApplicationContext()); ble_scanner.setDevice_name_start(DEVICE_NAME_START); ble_scanner.setSelect_bonded_devices_only(true); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (ble_scanning) { setScanState(false); ble_scanner.stopScanning(); } BluetoothDevice device = ble_device_list_adapter.getDevice(position); if (device.getBondState() == BluetoothDevice.BOND_NONE && Settings.getInstance().isFilter_unpaired_devices()) { device.createBond(); showMsg(Utility.htmlColorRed("Selected micro:bit must be paired - pairing now")); return; } try { MainActivity.this.unregisterReceiver(broadcastReceiver); } catch (Exception e) { // ignore! } if (toast != null) { toast.cancel(); } MicroBit microbit = MicroBit.getInstance(); microbit.setBluetooth_device(device); Intent intent = new Intent(MainActivity.this, MenuActivity.class); intent.putExtra(MenuActivity.EXTRA_NAME, device.getName()); intent.putExtra(MenuActivity.EXTRA_ID, device.getAddress()); startActivity(intent); } }); }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
@Receiver(actions = BluetoothDevice.ACTION_BOND_STATE_CHANGED) void onBondStateChanged(Intent intent) { final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); final int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1); final int previousBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1); Log.d(TAG, "Bond state changed for: " + device.getAddress() + " new state: " + bondState + " previous: " + previousBondState);//from w w w . j a va 2 s .c o m if (bondState == BluetoothDevice.BOND_BONDED) { Log.i(TAG, "Bonded"); createGATT(device); } else if (bondState == BluetoothDevice.BOND_NONE) { device.createBond(); } }
From source file:com.wolkabout.hexiwear.activity.MainActivity.java
@Receiver(actions = BluetoothDevice.ACTION_BOND_STATE_CHANGED) void onBondStateChanged(Intent intent) { final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); final int previousBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1); final int newBondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1); Log.d(TAG, device.getName() + "(" + device.getAddress() + ") changed state: " + previousBondState + " -> " + newBondState);/* w w w. jav a2s.c o m*/ adapter.notifyDataSetChanged(); if (newBondState == BluetoothDevice.BOND_BONDED) { onBonded(device); } else if (previousBondState == BluetoothDevice.BOND_BONDING && newBondState == BluetoothDevice.BOND_NONE) { device.createBond(); } }
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeGattPeripheral.java
@NonNull @Override//ww w . j a va 2s . co m @RequiresPermission(allOf = { Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN, }) public Observable<GattPeripheral> removeBond(final @NonNull OperationTimeout timeout) { return createObservable(new Observable.OnSubscribe<GattPeripheral>() { @Override public void call(final Subscriber<? super GattPeripheral> subscriber) { if (getBondStatus() != BOND_BONDED) { logger.info(GattPeripheral.LOG_TAG, "Device not bonded, skipping."); subscriber.onNext(NativeGattPeripheral.this); subscriber.onCompleted(); return; } final Subscription subscription = createBondReceiver().subscribe(new Subscriber<Intent>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { subscriber.onError(e); } @Override public void onNext(Intent intent) { timeout.reschedule(); final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR); final int previousState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR); logger.info(GattPeripheral.LOG_TAG, "Bond status changed from " + BondException.getBondStateString(previousState) + " to " + BondException.getBondStateString(state)); if (state == BluetoothDevice.BOND_NONE) { logger.info(LOG_TAG, "Removing bond succeeded."); timeout.unschedule(); subscriber.onNext(NativeGattPeripheral.this); subscriber.onCompleted(); unsubscribe(); } else if (state == BluetoothDevice.ERROR) { timeout.unschedule(); final int reason = intent.getIntExtra(BondException.EXTRA_REASON, BondException.REASON_UNKNOWN_FAILURE); logger.error(LOG_TAG, "Removing bond failed for reason " + BondException.getReasonString(reason), null); subscriber.onError(new BondException(reason)); unsubscribe(); } } }); timeout.setTimeoutAction(new Action0() { @Override public void call() { subscription.unsubscribe(); // This can happen in Lollipop if (getBondStatus() == BOND_NONE) { subscriber.onNext(NativeGattPeripheral.this); subscriber.onCompleted(); } else { subscriber.onError(new OperationTimeoutException(Operation.REMOVE_BOND)); } } }, stack.getScheduler()); if (!BluetoothDeviceCompat.removeBond(bluetoothDevice)) { subscription.unsubscribe(); subscriber.onError(new BondException(BondException.REASON_ANDROID_API_CHANGED)); } else { timeout.schedule(); } } }); }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
/** * Handles intents ACTION_CONNECTION_STATE_CHANGED, ACTION_STATE_CHANGED, * ACTION_BOND_STATE_CHANGED, ACTION_KEYBOARD_UPDATE_CONFIRMED. * <p/>// w ww. j a v a 2 s . c o m * [ACTION_STATE_CHANGED] * This action is used to keep track of ON/OFF state change on the system Bluetooth adapter. * The * purpose is to synchronize the local Bluetooth connectivity with system Bluetooth state. * <p/> * [ACTION_CONNECTION_STATE_CHANGED] * This action is used to keep track of the connection change on the target device. The purpose * is to synchronize the connection cycles of the local GATT connection and the system * Bluetooth * connection. * <p/> * [ACTION_BOND_STATE_CHANGED] * This action is used to keep track of the bond state change on the target device. The purpose * is to the connection cycles of the local GATT connection and the system Bluetooth * connection. * <p/> * [ACTION_KEYBOARD_UPDATE_CONFIRMED] * This action is used to receive the update confirmation from the user. The purpose is to * trigger DFU process. */ private void onHandleIntent(Context context, Intent intent) { final String action = intent.getAction(); Log.d(TAG, "onHandleIntent: Received action: " + action); if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { if (!isBluetoothEnabled()) { Log.w(TAG, "onHandleIntent: Bluetooth connectivity not enabled"); return; } // Match the connected device with the default keyboard name. Bundle extras = intent.getExtras(); if (extras == null) return; final BluetoothDevice device = extras.getParcelable(BluetoothDevice.EXTRA_DEVICE); final int deviceConnectionState = extras.getInt(BluetoothAdapter.EXTRA_CONNECTION_STATE); Log.d(TAG, "onHandleIntent: " + device.getName() + " [" + device.getAddress() + "] change to state: " + deviceConnectionState); // Match the name of the target keyboard. if (!isTargetKeyboard(device)) return; if (deviceConnectionState == BluetoothAdapter.STATE_CONNECTED) { // Prevent the second keyboard from using the service. if (isUpdateServiceInUse()) return; obtainKeyboardInfo(device.getName(), device.getAddress()); if (mDfuStatus != DFU_STATE_INFO_READY) { Log.w(TAG, "onHandleIntent: DFU preparation failed"); changeDfuStatus(DFU_STATE_OBTAIN_INFO_ERROR); return; } showUpdateNotification(); } else if (deviceConnectionState == BluetoothAdapter.STATE_DISCONNECTING) { handleGattDisconnection(); } } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) { final int adapterState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); if (adapterState == BluetoothAdapter.STATE_ON) { if (!isBluetoothEnabled()) enableBluetoothConnectivity(); } else if (adapterState == BluetoothAdapter.STATE_TURNING_OFF) { // Terminate update process and disable Bluetooth connectivity. disableBluetoothConnectivity(); // Since BluetoothAdapter has been disabled, the callback of disconnection would not // be called. Therefore a separate clean-up of GATT connection is need. cleanUpGattConnection(); } } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { Bundle extras = intent.getExtras(); if (extras == null) return; final BluetoothDevice device = extras.getParcelable(BluetoothDevice.EXTRA_DEVICE); final int deviceBondState = extras.getInt(BluetoothDevice.EXTRA_BOND_STATE); Log.d(TAG, "onHandleIntent: state change on device " + device.getName() + " [" + device.getAddress() + "], bond state: " + deviceBondState); if (!isTargetKeyboard(device)) return; if (deviceBondState == BluetoothDevice.BOND_NONE) { handleGattDisconnection(); } } else if (ACTION_KEYBOARD_UPDATE_CONFIRMED.equals(action)) { dismissUpdateNotification(); if (mDfuStatus != DFU_STATE_INFO_READY || mDfuStatus == DFU_STATE_UPDATING) { Log.w(TAG, "onHandleIntent: DFP preparation not ready or DFU is in progress. "); changeDfuStatus(DFU_STATE_UPDATE_ABORTED); return; } String keyboardName = intent.getStringExtra(EXTRA_KEYBOARD_NAME); String keyboardAddress = intent.getStringExtra(EXTRA_KEYBOARD_ADDRESS); if (!mKeyboardName.equals(keyboardName) || !mKeyboardAddress.equals(keyboardAddress)) { Log.w(TAG, "onHandleIntent: No DFU service associated with " + keyboardName + " [" + keyboardAddress + "]"); return; } Log.d(TAG, "onHandleIntent: Start update process on " + keyboardName + " [" + keyboardAddress + "]"); changeDfuStatus(DFU_STATE_SWITCHING_TO_DFU_MODE); } else if (ACTION_KEYBOARD_UPDATE_POSTPONED.equals(action)) { dismissUpdateNotification(); // TODO(mcchou): Update the preference when the Settings keyboard entry is available. } }