List of usage examples for android.bluetooth BluetoothGattCharacteristic getPermissions
public int getPermissions()
From source file:Main.java
public static JSONArray decodePermissions(BluetoothGattCharacteristic characteristic) { // NOTE: props strings need to be consistent across iOS and Android JSONArray props = new JSONArray(); int permissions = characteristic.getPermissions(); if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ) != 0x0) { props.put("Read"); }/*from w w w. j a v a 2s.c om*/ if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE) != 0x0) { props.put("Write"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED) != 0x0) { props.put("ReadEncrypted"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED) != 0x0) { props.put("WriteEncrypted"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM) != 0x0) { props.put("ReadEncryptedMITM"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM) != 0x0) { props.put("WriteEncryptedMITM"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED) != 0x0) { props.put("WriteSigned"); } if ((permissions & BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM) != 0x0) { props.put("WriteSignedMITM"); } return props; }
From source file:Main.java
public static String getReadableCharacteristicProperties(BluetoothGattCharacteristic c) { List<String> qualities = new ArrayList<String>(); StringBuilder s = new StringBuilder(); int cProps = c.getProperties(); for (Object[] property : properties) { if ((cProps & ((Integer) property[0])) != 0) { s.append((String) property[1]); s.append('\n'); }//from www .j av a 2 s . c o m } int cPerms = c.getPermissions(); for (Object[] permission : permissions) { if ((cProps & ((Integer) permission[0])) != 0) { s.append((String) permission[1]); s.append('\n'); } } return s.toString(); }
From source file:com.evothings.BLE.java
private void characteristics(final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { final GattHandler gh = mGatt.get(args.getInt(0)); JSONArray a = new JSONArray(); for (BluetoothGattCharacteristic c : gh.mServices.get(args.getInt(1)).getCharacteristics()) { if (gh.mCharacteristics == null) gh.mCharacteristics = new HashMap<Integer, BluetoothGattCharacteristic>(); Object res = gh.mCharacteristics.put(gh.mNextHandle, c); assert (res == null); JSONObject o = new JSONObject(); o.put("handle", gh.mNextHandle); o.put("uuid", c.getUuid().toString()); o.put("permissions", c.getPermissions()); o.put("properties", c.getProperties()); o.put("writeType", c.getWriteType()); gh.mNextHandle++;/* www . j a v a2s . c om*/ a.put(o); } callbackContext.success(a); }
From source file:com.megster.cordova.ble.central.Peripheral.java
public JSONObject asJSONObject(BluetoothGatt gatt) { JSONObject json = asJSONObject();// ww w .ja va 2 s . c om try { JSONArray servicesArray = new JSONArray(); JSONArray characteristicsArray = new JSONArray(); json.put("services", servicesArray); json.put("characteristics", characteristicsArray); if (connected && gatt != null) { for (BluetoothGattService service : gatt.getServices()) { servicesArray.put(UUIDHelper.uuidToString(service.getUuid())); for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) { JSONObject characteristicsJSON = new JSONObject(); characteristicsArray.put(characteristicsJSON); characteristicsJSON.put("service", UUIDHelper.uuidToString(service.getUuid())); characteristicsJSON.put("characteristic", UUIDHelper.uuidToString(characteristic.getUuid())); //characteristicsJSON.put("instanceId", characteristic.getInstanceId()); characteristicsJSON.put("properties", Helper.decodeProperties(characteristic)); // characteristicsJSON.put("propertiesValue", characteristic.getProperties()); if (characteristic.getPermissions() > 0) { characteristicsJSON.put("permissions", Helper.decodePermissions(characteristic)); // characteristicsJSON.put("permissionsValue", characteristic.getPermissions()); } JSONArray descriptorsArray = new JSONArray(); for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) { JSONObject descriptorJSON = new JSONObject(); descriptorJSON.put("uuid", UUIDHelper.uuidToString(descriptor.getUuid())); descriptorJSON.put("value", descriptor.getValue()); // always blank if (descriptor.getPermissions() > 0) { descriptorJSON.put("permissions", Helper.decodePermissions(descriptor)); // descriptorJSON.put("permissionsValue", descriptor.getPermissions()); } descriptorsArray.put(descriptorJSON); } if (descriptorsArray.length() > 0) { characteristicsJSON.put("descriptors", descriptorsArray); } } } } } catch (JSONException e) { // TODO better error handling e.printStackTrace(); } return json; }