use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class PebblePairingActivity method getMatchingParentDeviceFromDB.
private GBDevice getMatchingParentDeviceFromDB(BluetoothDevice btDevice) {
String expectedSuffix = btDevice.getName();
expectedSuffix = expectedSuffix.replace("Pebble-LE ", "");
expectedSuffix = expectedSuffix.replace("Pebble Time LE ", "");
expectedSuffix = expectedSuffix.substring(0, 2) + ":" + expectedSuffix.substring(2);
LOG.info("will try to find a Pebble with BT address suffix " + expectedSuffix);
GBDevice gbDevice = null;
try (DBHandler dbHandler = GBApplication.acquireDB()) {
DaoSession session = dbHandler.getDaoSession();
DeviceDao deviceDao = session.getDeviceDao();
Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Type.eq(1), DeviceDao.Properties.Identifier.like("%" + expectedSuffix)).build();
List<Device> devices = query.list();
if (devices.size() == 0) {
GB.toast("Please pair your non-LE Pebble before pairing the LE one", Toast.LENGTH_SHORT, GB.INFO);
returnToPairingActivity();
return null;
} else if (devices.size() > 1) {
GB.toast("Can not match this Pebble LE to a unique device", Toast.LENGTH_SHORT, GB.INFO);
returnToPairingActivity();
return null;
}
DeviceHelper deviceHelper = DeviceHelper.getInstance();
gbDevice = deviceHelper.toGBDevice(devices.get(0));
gbDevice.setVolatileAddress(btDevice.getAddress());
} catch (Exception e) {
GB.toast("Error retrieving devices from database", Toast.LENGTH_SHORT, GB.ERROR);
returnToPairingActivity();
return null;
}
return gbDevice;
}
use of android.bluetooth.BluetoothDevice in project Gadgetbridge by Freeyourgadget.
the class MiBand2Coordinator method getSupportedType.
@NonNull
@Override
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
if (candidate.supportsService(MiBand2Service.UUID_SERVICE_MIBAND2_SERVICE)) {
return DeviceType.MIBAND2;
}
// and a heuristic for now
try {
BluetoothDevice device = candidate.getDevice();
// if (isHealthWearable(device)) {
String name = device.getName();
if (name != null && name.equalsIgnoreCase(MiBandConst.MI_BAND2_NAME)) {
return DeviceType.MIBAND2;
}
// }
} catch (Exception ex) {
LOG.error("unable to check device support", ex);
}
return DeviceType.UNKNOWN;
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.
the class BluetoothController method updateBondedBluetoothDevices.
private void updateBondedBluetoothDevices() {
mBondedDevices.clear();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
Set<BluetoothDevice> devices = adapter.getBondedDevices();
if (devices != null) {
for (BluetoothDevice device : devices) {
if (device.getBondState() != BluetoothDevice.BOND_NONE) {
mBondedDevices.add(device);
}
}
}
}
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.
the class BluetoothGatt method writeCharacteristic.
/**
* Writes a given characteristic and its values to the associated remote device.
*
* <p>Once the write operation has been completed, the
* {@link BluetoothGattCallback#onCharacteristicWrite} callback is invoked,
* reporting the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param characteristic Characteristic to write on the remote device
* @return true, if the write operation was initiated successfully
*/
public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) {
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0 && (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == 0)
return false;
if (DBG)
Log.d(TAG, "writeCharacteristic() - uuid: " + characteristic.getUuid());
if (mService == null || mClientIf == 0)
return false;
BluetoothGattService service = characteristic.getService();
if (service == null)
return false;
BluetoothDevice device = service.getDevice();
if (device == null)
return false;
try {
mService.writeCharacteristic(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), characteristic.getWriteType(), AUTHENTICATION_NONE, characteristic.getValue());
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
}
return true;
}
use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.
the class BluetoothGatt method setCharacteristicNotification.
/**
* Enable or disable notifications/indications for a given characteristic.
*
* <p>Once notifications are enabled for a characteristic, a
* {@link BluetoothGattCallback#onCharacteristicChanged} callback will be
* triggered if the remote device indicates that the given characteristic
* has changed.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param characteristic The characteristic for which to enable notifications
* @param enable Set to true to enable notifications/indications
* @return true, if the requested notification status was set successfully
*/
public boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable) {
if (DBG)
Log.d(TAG, "setCharacteristicNotification() - uuid: " + characteristic.getUuid() + " enable: " + enable);
if (mService == null || mClientIf == 0)
return false;
BluetoothGattService service = characteristic.getService();
if (service == null)
return false;
BluetoothDevice device = service.getDevice();
if (device == null)
return false;
try {
mService.registerForNotification(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), enable);
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
}
return true;
}
Aggregations