Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#PROPERTY_READ
The following examples show how to use
android.bluetooth.BluetoothGattCharacteristic#PROPERTY_READ .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceControlActivity.java From connectivity-samples with Apache License 2.0 | 6 votes |
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mGattCharacteristics != null) { final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition); 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) { mBluetoothLeService.setCharacteristicNotification( mNotifyCharacteristic, false); mNotifyCharacteristic = null; } mBluetoothLeService.readCharacteristic(characteristic); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; mBluetoothLeService.setCharacteristicNotification( characteristic, true); } return true; } return false; }
Example 2
Source File: P_DeviceServiceManager.java From AsteroidOSSync with GNU General Public License v3.0 | 6 votes |
private static int getProperty(BleDevice.ReadWriteListener.Type type) { switch(type) { case READ: case POLL: case PSUEDO_NOTIFICATION: return BluetoothGattCharacteristic.PROPERTY_READ; case WRITE_NO_RESPONSE: return BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE; case WRITE_SIGNED: return BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE; case WRITE: return BluetoothGattCharacteristic.PROPERTY_WRITE; case ENABLING_NOTIFICATION: case DISABLING_NOTIFICATION: case NOTIFICATION: case INDICATION: return BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_NOTIFY ; } return 0x0; }
Example 3
Source File: BluetoothLeDeviceBase.java From BlogPracticeDems with Apache License 2.0 | 6 votes |
private void setNotify(BluetoothGattCharacteristic characteristic) { 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 (mNotifyCharacteristic1 != null) { setCharacteristicNotification( mNotifyCharacteristic1, false); mNotifyCharacteristic1 = null; } readCharacteristic(characteristic); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic1 = characteristic; setCharacteristicNotification( characteristic, true); } }
Example 4
Source File: BleGattImpl.java From EasyBle with Apache License 2.0 | 6 votes |
private Map<ServiceInfo, List<CharacteristicInfo>> getServiceInfoMap(List<BluetoothGattService> gattServices) { Map<ServiceInfo, List<CharacteristicInfo>> servicesInfoMap = new HashMap<>(); for (BluetoothGattService service : gattServices) { String uuid = service.getUuid().toString(); ServiceInfo serviceInfo = new ServiceInfo(uuid); List<CharacteristicInfo> charactInfos = new ArrayList<>(); for (BluetoothGattCharacteristic ch : service.getCharacteristics()) { String chUuid = ch.getUuid().toString(); boolean readable = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) > 0; boolean writable = (ch.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) > 0; boolean notify = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0; boolean indicate = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0; CharacteristicInfo charactInfo = new CharacteristicInfo(chUuid, readable, writable, notify, indicate); charactInfos.add(charactInfo); } servicesInfoMap.put(serviceInfo, charactInfos); } return servicesInfoMap; }
Example 5
Source File: P_DeviceServiceManager.java From SweetBlue with GNU General Public License v3.0 | 6 votes |
private static int getProperty(BleDevice.ReadWriteListener.Type type) { switch(type) { case READ: case POLL: case PSUEDO_NOTIFICATION: return BluetoothGattCharacteristic.PROPERTY_READ; case WRITE_NO_RESPONSE: return BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE; case WRITE_SIGNED: return BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE; case WRITE: return BluetoothGattCharacteristic.PROPERTY_WRITE; case ENABLING_NOTIFICATION: case DISABLING_NOTIFICATION: case NOTIFICATION: case INDICATION: return BluetoothGattCharacteristic.PROPERTY_INDICATE | BluetoothGattCharacteristic.PROPERTY_NOTIFY ; } return 0x0; }
Example 6
Source File: AbstractHOGPServer.java From DeviceConnect-Android with MIT License | 6 votes |
@Override public void onCharacteristicWriteRequest(final BluetoothDevice device, final int requestId, final BluetoothGattCharacteristic characteristic, final boolean preparedWrite, final boolean responseNeeded, final int offset, final byte[] value) { if (DEBUG) { Log.d(TAG, "onCharacteristicWriteRequest characteristic: " + characteristic.getUuid() + ", value: " + Arrays.toString(value)); } if (mGattServer == null) { return; } if (responseNeeded) { if (BleUuidUtils.matches(CHARACTERISTIC_REPORT, characteristic.getUuid())) { if (characteristic.getProperties() == (BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_WRITE | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) { onOutputReport(value); } mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, EMPTY_BYTES); } else { mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_FAILURE, 0, EMPTY_BYTES); } } }
Example 7
Source File: ReadAllCommand.java From neatle with MIT License | 5 votes |
@Override protected void start(Connection connection, BluetoothGatt gatt) { List<BluetoothGattService> services = gatt.getServices(); for (BluetoothGattService service : services) { List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic characteristic : characteristics) { int props = characteristic.getProperties(); if ((props & BluetoothGattCharacteristic.PROPERTY_READ) != 0) { queue.add(characteristic); } } } readNext(gatt); }
Example 8
Source File: BleManagerHandler.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean internalReadCharacteristic(@Nullable final BluetoothGattCharacteristic characteristic) { final BluetoothGatt gatt = bluetoothGatt; if (gatt == null || characteristic == null || !connected) return false; // Check characteristic property. final int properties = characteristic.getProperties(); if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) == 0) return false; log(Log.VERBOSE, "Reading characteristic " + characteristic.getUuid()); log(Log.DEBUG, "gatt.readCharacteristic(" + characteristic.getUuid() + ")"); return gatt.readCharacteristic(characteristic); }
Example 9
Source File: BleGattImpl.java From EasyBle with Apache License 2.0 | 5 votes |
@Override public void read(final BleDevice device, String serviceUuid, String readUuid, final BleReadCallback callback) { checkNotNull(callback, BleReadCallback.class); if (!checkConnection(device, callback)) { return; } BluetoothGatt gatt = mGattMap.get(device.address); if (!checkUuid(serviceUuid, readUuid, gatt, device, callback)) { return; } OperationIdentify identify = getOperationIdentifyFromMap(mReadCallbackMap, device.address, serviceUuid, readUuid); if (identify != null) { mReadCallbackMap.put(identify, callback); } else { mReadCallbackMap.put(new OperationIdentify(device.address, serviceUuid, readUuid), callback); } BluetoothGattService service = gatt.getService(UUID.fromString(serviceUuid)); BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(readUuid)); boolean readable = (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) > 0; if (!readable) { mHandler.post(new Runnable() { @Override public void run() { callback.onFailure(BleCallback.FAIL_OTHER, "the characteristic is not readable", device); } }); return; } if (!gatt.readCharacteristic(characteristic)) { mHandler.post(new Runnable() { @Override public void run() { callback.onFailure(BleCallback.FAIL_OTHER, "read fail because of unknown reason", device); } }); } }
Example 10
Source File: DeviceControlActivity.java From BlunoAccessoryShieldDemo with GNU General Public License v3.0 | 5 votes |
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mGattCharacteristics != null) { final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition); int charaProp = characteristic.getProperties(); System.out.println("onChildClick "+characteristic.getUuid().toString()+" "+charaProp); if(characteristic.getUuid().toString().equals("0000ffe1-0000-1000-8000-00805f9b34fb")){ mBluetoothLeService.setCharacteristicNotification( characteristic, true); } 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) { mBluetoothLeService.setCharacteristicNotification( mNotifyCharacteristic, true); mNotifyCharacteristic = null; }*/ characteristic.setValue("01234567890123456789"); mBluetoothLeService.writeCharacteristic(characteristic); mBluetoothLeService.readCharacteristic(characteristic); } if ((charaProp & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; //mBluetoothLeService.setCharacteristicNotification( // characteristic, true); } return true; } return false; }
Example 11
Source File: BleManager.java From BLEChat with GNU General Public License v3.0 | 5 votes |
private boolean isReadableCharacteristic(BluetoothGattCharacteristic chr) { if(chr == null) return false; final int charaProp = chr.getProperties(); if((charaProp & BluetoothGattCharacteristic.PROPERTY_READ) > 0) { Logs.d("# Found readable characteristic"); return true; } else { Logs.d("# Not readable characteristic"); return false; } }
Example 12
Source File: CharacteristicDetailsActivity.java From BLEService with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static String getCharacteristicPropertiesString(int props) { String propertiesString = String.format("0x%04X [", props); if((props & BluetoothGattCharacteristic.PROPERTY_READ) != 0) propertiesString += "read "; if((props & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) propertiesString += "write "; if((props & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) propertiesString += "notify "; if((props & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) propertiesString += "indicate "; if((props & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) propertiesString += "write_no_response "; propertiesString += "]"; return propertiesString; }
Example 13
Source File: GattReadWriteTests.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@Test public void writeCharacteristicTest() { final byte[] fakeData = new byte[]{'a','b','c','d','e','f','g','h','i', 'j'}; BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(UUID.randomUUID(), BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED); WriteGattCharacteristicMockTransaction writeChar = new WriteGattCharacteristicMockTransaction(conn, GattState.WRITE_CHARACTERISTIC_SUCCESS, characteristic, fakeData, false); conn.runTx(writeChar, result -> { assert(result.resultStatus.equals(TransactionResult.TransactionResultStatus.SUCCESS) && result.resultState.equals(writeChar.getSuccessState())); }); }
Example 14
Source File: GattServerTests.java From bitgatt with Mozilla Public License 2.0 | 5 votes |
@Test public void notifyGattServerWithNullPointerException() throws InterruptedException { CountDownLatch cdl = new CountDownLatch(1); TransactionResult.TransactionResultStatus[] results = new TransactionResult.TransactionResultStatus[1]; FitbitGatt.FitbitGattCallback callback = new NoOpGattCallback() { @Override public void onGattServerStarted(GattServerConnection serverConnection) { super.onGattServerStarted(serverConnection); FitbitBluetoothDevice fbtDevice = new FitbitBluetoothDevice(MOCK_ADDRESS, "foobar"); BluetoothGattCharacteristic notifChar = new BluetoothGattCharacteristic(UUID.fromString("16BCFD02-253F-C348-E831-0DB3E334D580"), BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED | BluetoothGattCharacteristic.PERMISSION_WRITE); NotifyGattServerCharacteristicMockTransaction notifyTx = new NotifyGattServerCharacteristicMockTransaction(serverConnection, fbtDevice, GattState.NOTIFY_CHARACTERISTIC_SUCCESS, notifChar, true, true); notifyTx.setShouldThrow(true); serverConnection.runTx(notifyTx, result -> { results[0] = result.resultStatus; cdl.countDown(); }); } }; FitbitGatt.getInstance().registerGattEventListener(callback); FitbitGatt.getInstance().startGattServer(mockContext); cdl.await(1, TimeUnit.SECONDS); assertEquals(TransactionResult.TransactionResultStatus.FAILURE, results[0]); assertEquals(GattState.IDLE, FitbitGatt.getInstance().getServer().getGattState()); }
Example 15
Source File: DeviceControlActivity.java From jessica with MIT License | 4 votes |
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mGattCharacteristics != null) { final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition).get(childPosition); final int charaProp = characteristic.getProperties(); // abuse A01 characteristics for start/stop Tour-the-Stairs thread if( characteristic.getUuid().toString().equals("9a66fa01-0800-9191-11e4-012d1540cb8e") ) { if (mTourTheStairs == null || mTourTheStairs.completed()) { mTourTheStairs = new TourTheStairs(mBluetoothLeService, mGattCharacteristics); mTourTheStairs.start(); } return true; } if( characteristic.getUuid().toString().equals("9a66fa02-0800-9191-11e4-012d1540cb8e") ) { if (mTourTheStairs != null ) { mTourTheStairs.requestStop(); } return true; } 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) { mBluetoothLeService.setCharacteristicNotification( mNotifyCharacteristic, false); mNotifyCharacteristic = null; } mBluetoothLeService.readCharacteristic(characteristic); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; mBluetoothLeService.setCharacteristicNotification( characteristic, true); } return true; } return false; }
Example 16
Source File: BluetoothUtilImpl.java From android-ponewheel with MIT License | 4 votes |
public static boolean isCharacteristicReadable(BluetoothGattCharacteristic c) { return ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0); }
Example 17
Source File: BleManager.java From Bluefruit_LE_Connect_Android with MIT License | 4 votes |
public boolean isCharacteristicReadable(BluetoothGattService service, String characteristicUUIDString) { final int properties = getCharacteristicProperties(service, characteristicUUIDString); final boolean isReadable = (properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0; return isReadable; }
Example 18
Source File: DiscoveryResultsAdapter.java From RxAndroidBle with Apache License 2.0 | 4 votes |
private boolean isCharacteristicReadable(BluetoothGattCharacteristic characteristic) { return ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) != 0); }
Example 19
Source File: GattDatabase.java From SweetBlue with GNU General Public License v3.0 | 4 votes |
public final Properties read() { m_properties |= BluetoothGattCharacteristic.PROPERTY_READ; return this; }
Example 20
Source File: Node.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * test if a characteristics can be read * @param characteristic characteristic to read * @return true if we can read it */ private static boolean charCanBeRead(BluetoothGattCharacteristic characteristic){ return characteristic!=null && (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ )!=0; }