List of usage examples for android.bluetooth BluetoothGatt getDevice
public BluetoothDevice getDevice()
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
private String getDeviceAddress(BluetoothGatt gatt) { return gatt.getDevice().getAddress(); }
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. *//* ww w. ja va 2s .co 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:com.beestar.ble.ble.ui.MultipleBleActivity.java
private void setBleServiceListener() { mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() { @Override/*from w w w. j av a2s .co m*/ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_DISCONNECTED) { for (int i = 0; i < deviceList.size(); i++) { HashMap<String, Object> devMap = (HashMap<String, Object>) deviceList.get(i); if (devMap.get("address").toString().equals(gatt.getDevice().getAddress())) { ((HashMap) deviceList.get(i)).put("isConnect", false); return; } } } else if (newState == BluetoothProfile.STATE_CONNECTING) { } else if (newState == BluetoothProfile.STATE_CONNECTED) { for (int i = 0; i < deviceList.size(); i++) { HashMap<String, Object> devMap = (HashMap<String, Object>) deviceList.get(i); if (devMap.get("address").toString().equals(gatt.getDevice().getAddress())) { ((HashMap) deviceList.get(i)).put("isConnect", true); return; } } } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { } } }); //?? mBleService.setOnServicesDiscoveredListener(new MultipleBleService.OnServicesDiscoveredListener() { @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { String characteristics_uuid_read = null; String characteristics_uuid_write = null; String read_Uuid = null; String write_Uuid = null; BluetoothGattCharacteristic characteristic; if (status == gatt.GATT_SUCCESS) { String address = gatt.getDevice().getAddress(); List<BluetoothGattService> services = gatt.getServices(); commonUtils = new CommonUtils(getApplicationContext()); int j, k; for (int i = 0; i < services.size(); i++) { if (services.get(i).getUuid().toString().contains("ffe5")) { write_Uuid = services.get(i).getUuid().toString(); Log.i("info", "--------------------" + i); characteristics_uuid_write = services.get(i).getCharacteristics().get(0).getUuid() .toString(); } if (services.get(i).getUuid().toString().contains("ffe0")) { Log.i("info", "--------------------" + i); characteristic = services.get(i).getCharacteristic(services.get(i).getUuid()); read_Uuid = services.get(i).getUuid().toString(); characteristics_uuid_read = services.get(i).getCharacteristics().get(0).getUuid() .toString(); } } Equipment_Device equipment_device = new Equipment_Device(); equipment_device.setAddress(address); equipment_device.setRead_uuid(read_Uuid); equipment_device.setRead_uuid(write_Uuid); equipment_device.setCh_read_uuid(characteristics_uuid_read); equipment_device.setCh_write_uuid(characteristics_uuid_write); commonUtils.insertStudent(equipment_device); } } }); mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { } }); mBleService.setOnDataAvailableListener(new MultipleBleService.OnDataAvailableListener() { @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { } @Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { } }); }