List of usage examples for android.bluetooth BluetoothGatt readCharacteristic
public boolean readCharacteristic(BluetoothGattCharacteristic characteristic)
From source file:ble.AndroidBle.java
public boolean readCharacteristic(String address, BleGattCharacteristic characteristic) { BluetoothGatt gatt = mBluetoothGatts.get(address); if (gatt == null) { return false; }/*from w w w. j a va2s.com*/ return gatt.readCharacteristic(characteristic.getGattCharacteristicA()); }
From source file:org.physical_web.physicalweb.BluetoothSite.java
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.i(TAG, "Services Discovered"); if (status != BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "Service discovery failed!"); return;/*from ww w . j a v a 2 s .c om*/ } try { mHtml = new FileOutputStream(getHtmlFile()); } catch (FileNotFoundException e) { Log.e(TAG, "File not found", e); return; } characteristic = gatt.getService(SERVICE_UUID).getCharacteristic(CHARACTERISTIC_WEBPAGE_UUID); gatt.readCharacteristic(characteristic); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
void readValue(String address, BluetoothGattCharacteristic theCharacteristic) { BluetoothGatt bluetoothGatt = addressToGattClient.get(address); if (bluetoothGatt == null) { Log.w(TAG, "No connection found for: " + address); sendGattBroadcast(address, BleEvents.READ_CHAR_FAIL, null); return;/* www . j av a 2 s . c om*/ } bluetoothGatt.readCharacteristic(theCharacteristic); }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
private void readCharacteristic(final BluetoothGatt gatt, final Characteristic characteristic) { if (!isConnected) { return;/*from w ww . jav a2s. co m*/ } final BluetoothGattCharacteristic gattCharacteristic = readableCharacteristics .get(characteristic.getUuid()); if (gattCharacteristic != null) { gatt.readCharacteristic(gattCharacteristic); } }
From source file:org.physical_web.physicalweb.BluetoothSite.java
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // Make sure the site is running. It can stop if the dialog is dismissed very quickly. if (!isRunning()) { close();//from www. ja va 2s.c o m return; } // Make sure the read was successful. if (status != BluetoothGatt.GATT_SUCCESS) { Log.i(TAG, "onCharacteristicRead unsuccessful: " + status); close(); Toast.makeText(activity, R.string.ble_download_error_message, Toast.LENGTH_SHORT).show(); return; } // Record the data. Log.i(TAG, "onCharacteristicRead successful"); try { mHtml.write(characteristic.getValue()); } catch (IOException e) { Log.e(TAG, "Could not write to buffer", e); close(); return; } // Request a new read if we are not done. if (characteristic.getValue().length == transferRate) { gatt.readCharacteristic(this.characteristic); return; } // At this point we are done. Show the file. Log.i(TAG, "transfer is complete"); close(); openInChrome(getHtmlFile()); }
From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java
private boolean readCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { if (null == characteristic) return false; final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { // If there is an active notification on a characteristic, // clear it first so it doesn't update the data field on the user interface. if (mNotifyCharacteristic != null) { bleService.setCharacteristicNotification(gatt, mNotifyCharacteristic, false); mNotifyCharacteristic = null; }/* www . ja va 2s . com*/ //JS: if no data is displayed, immediately read data from the connected sensor. gatt.readCharacteristic(characteristic); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; bleService.setCharacteristicNotification(gatt, characteristic, true); } return true; }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
/** * Request a read on a given {@code BluetoothGattCharacteristic}. The read result is reported * asynchronously through the {@code BluetoothGattCallback#onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)} * callback./*ww w . j a va 2s . c om*/ * */ public boolean readCharacteristic(String address, String serviceUuid, String characteristicUuid) { Log.d(TAG, "readCharacteristic add = " + address + ", svc = " + serviceUuid + ", char = " + characteristicUuid); if (StringUtils.isEmptyString(address) || StringUtils.isEmptyString(serviceUuid) || StringUtils.isEmptyString(characteristicUuid)) { Log.w(TAG, "Unknown parameter"); return false; } BluetoothGatt bluetoothGatt = mConnectedBluetoothGattMap.get(address); if (mBluetoothAdapter == null || bluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return false; } BluetoothGattService service = bluetoothGatt.getService(UUID.fromString(serviceUuid)); if (service == null) { Log.w(TAG, "Service not found."); return false; } BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(characteristicUuid)); if (characteristic == null) { Log.w(TAG, "characteristic not found."); return false; } boolean result = bluetoothGatt.readCharacteristic(characteristic); Log.d(TAG, "Read charac uuid = " + characteristic.getUuid().toString() + ", result = " + result); return result; }