Example usage for android.bluetooth BluetoothDevice BOND_BONDED

List of usage examples for android.bluetooth BluetoothDevice BOND_BONDED

Introduction

In this page you can find the example usage for android.bluetooth BluetoothDevice BOND_BONDED.

Prototype

int BOND_BONDED

To view the source code for android.bluetooth BluetoothDevice BOND_BONDED.

Click Source Link

Document

Indicates the remote device is bonded (paired).

Usage

From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java

private void subscribeBluetoothDiscovery() {
    mSubscriptions.add(// ww w  .  j  av  a  2 s. c  o  m
            RxBluetoothBroadcastReceiver.bluetoothDeviceFound(getActivity()).subscribeOn(Schedulers.newThread())
                    // should run on UI thread (main thread) to change UI components
                    .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Intent>() {
                        @Override
                        public void onCompleted() {
                        }

                        @Override
                        public void onError(Throwable e) {
                        }

                        @Override
                        public void onNext(Intent intent) {
                            BluetoothDevice bluetoothDevice = intent
                                    .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                            if (bluetoothDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
                                return;
                            }

                            BluetoothMachineListAdapter adapter = (BluetoothMachineListAdapter) mNewDevicesListView
                                    .getAdapter();

                            if (adapter.contains(bluetoothDevice)) {
                                return;
                            }

                            adapter.add(bluetoothDevice);
                            adapter.notifyDataSetChanged();
                        }
                    }));

    mSubscriptions.add(RxBluetoothBroadcastReceiver.bluetoothDiscoveryFinished(getActivity())
            .observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.newThread())
            .subscribe(new Observer<Intent>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(Intent intent) {
                    // enable continuous discovering
                    BluetoothAdapter.getDefaultAdapter().startDiscovery();
                }
            }));
}

From source file:com.example.RITW.Ble.BleProfileService.java

@Override
public void onBonded() {
    //      Logger.i(mLogSession, "Bond state: Bonded");
    showToast(R.string.bonded);/*from   ww  w .j a  va  2s .  co  m*/

    final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
    broadcast.putExtra(EXTRA_BOND_STATE, BluetoothDevice.BOND_BONDED);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}

From source file:no.android.proxime.profile.BleProfileService.java

@Override
public void onBonded() {
    Logger.i(mLogSession, "Bond state: Bonded");
    showToast(R.string.bonded);/*  w w  w . java 2s.co m*/

    final Intent broadcast = new Intent(BROADCAST_BOND_STATE);
    broadcast.putExtra(EXTRA_BOND_STATE, BluetoothDevice.BOND_BONDED);
    LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
}

From source file:de.blinkt.openvpn.bluetooth.service.UartService.java

/**
 * When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
 * In case one of the requirements is not fulfilled this method returns <code>false</code>.
 *
 * @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
 * the Service Changed characteristic or this characteristic does not have the CCCD.
 *//*from www . j  ava 2  s.  c  o  m*/
public boolean ensureServiceChangedEnabled() {
    final BluetoothGatt gatt = mBluetoothGatt;
    if (gatt == null)
        return false;

    // The Service Changed indications have sense only on bonded devices
    final BluetoothDevice device = gatt.getDevice();
    if (device.getBondState() != BluetoothDevice.BOND_BONDED)
        return false;

    final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
    if (gaService == null)
        return false;

    final BluetoothGattCharacteristic scCharacteristic = gaService
            .getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
    return scCharacteristic != null;
}

From source file:is.hello.buruberi.bluetooth.stacks.android.NativeGattPeripheral.java

@NonNull
@Override//w ww.  j a va 2 s  .c o  m
@RequiresPermission(allOf = { Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN, })
public Observable<GattPeripheral> createBond() {
    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 already 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) {
                    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_BONDED) {
                        logger.info(LOG_TAG, "Bonding succeeded.");

                        subscriber.onNext(NativeGattPeripheral.this);
                        subscriber.onCompleted();

                        unsubscribe();
                    } else if (state == BluetoothDevice.ERROR
                            || state == BOND_NONE && previousState == BOND_CHANGING) {
                        final int reason = intent.getIntExtra(BondException.EXTRA_REASON,
                                BondException.REASON_UNKNOWN_FAILURE);
                        logger.error(LOG_TAG,
                                "Bonding failed for reason " + BondException.getReasonString(reason), null);
                        subscriber.onError(new BondException(reason));

                        unsubscribe();
                    }
                }
            });

            if (!BluetoothDeviceCompat.createBond(bluetoothDevice)) {
                subscription.unsubscribe();
                subscriber.onError(new BondException(BondException.REASON_ANDROID_API_CHANGED));
            }
        }
    });
}