List of usage examples for android.bluetooth BluetoothGattCharacteristic PROPERTY_INDICATE
int PROPERTY_INDICATE
To view the source code for android.bluetooth BluetoothGattCharacteristic PROPERTY_INDICATE.
Click Source Link
From source file:Main.java
public static JSONArray decodeProperties(BluetoothGattCharacteristic characteristic) { // NOTE: props strings need to be consistent across iOS and Android JSONArray props = new JSONArray(); int properties = characteristic.getProperties(); if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0) { props.put("Broadcast"); }// ww w .j a v a 2 s . c o m if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0) { props.put("Read"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0) { props.put("WriteWithoutResponse"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0) { props.put("Write"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0) { props.put("Notify"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0) { props.put("Indicate"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0) { // Android calls this "write with signature", using iOS name for now props.put("AuthenticateSignedWrites"); } if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0) { props.put("ExtendedProperties"); } // iOS only? // // if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) { // 0x100 // [props addObject:@"NotifyEncryptionRequired"]; // } // // if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) { // 0x200 // [props addObject:@"IndicateEncryptionRequired"]; // } return props; }
From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorDetails.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.gattdb_descriptor_details, container, false); this.mContainer = container; mApplication = (CySmartApplication) getActivity().getApplication(); mCharacteristicName = (TextView) rootView.findViewById(R.id.txtcharacteristicname); mDescriptorName = (TextView) rootView.findViewById(R.id.txtdescriptorname); mDescriptorValue = (TextView) rootView.findViewById(R.id.txtdescriptorvalue); mHexValue = (TextView) rootView.findViewById(R.id.txtdescriptorHexvalue); mBackBtn = (ImageView) rootView.findViewById(R.id.imgback); mProgressDialog = new ProgressDialog(getActivity()); mBluetoothGattCharacteristic = mApplication.getBluetoothgattcharacteristic(); String CharacteristicUUID = mBluetoothGattCharacteristic.getUuid().toString(); mCharacteristicName.setText(GattAttributes.lookup(CharacteristicUUID, CharacteristicUUID)); mDescriptor = mApplication.getBluetoothgattDescriptor(); String DescriptorUUID = mDescriptor.getUuid().toString(); mDescriptorName.setText(GattAttributes.lookup(DescriptorUUID, DescriptorUUID)); mReadButton = (Button) rootView.findViewById(R.id.btn_read); mNotifyButton = (Button) rootView.findViewById(R.id.btn_write_notify); mIndicateButton = (Button) rootView.findViewById(R.id.btn_write_indicate); if (DescriptorUUID.equalsIgnoreCase(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)) { if (getGattCharacteristicsPropertices(mBluetoothGattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_NOTIFY)) { mNotifyButton.setVisibility(View.VISIBLE); mNotifyButton.setText(getResources().getString(R.string.gatt_services_notify)); }/*from w w w .j a va 2s .c om*/ if (getGattCharacteristicsPropertices(mBluetoothGattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_INDICATE)) { mIndicateButton.setVisibility(View.VISIBLE); mIndicateButton.setText(getResources().getString(R.string.gatt_services_indicate)); } } else { mNotifyButton.setVisibility(View.GONE); } startNotifyText = getResources().getString(R.string.gatt_services_notify); stopNotifyText = getResources().getString(R.string.gatt_services_stop_notify); startIndicateText = getResources().getString(R.string.gatt_services_indicate); stopIndicateText = getResources().getString(R.string.gatt_services_stop_indicate); mReadButton.setOnClickListener(this); mNotifyButton.setOnClickListener(this); mIndicateButton.setOnClickListener(this); mBackBtn.setOnClickListener(this); if (mDescriptor != null) { BluetoothLeService.readDescriptor(mDescriptor); } return rootView; }
From source file:com.cypress.cysmart.BLEServiceFragments.HealthTemperatureService.java
/** * Stopping Broadcast receiver to broadcast notify characteristics * * @param gattCharacteristic//from w w w.ja v a2s . c o m */ void stopBroadcastDataIndiacte(BluetoothGattCharacteristic gattCharacteristic) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { if (mNotifyCharacteristic != null) { BluetoothLeService.setCharacteristicIndication(mNotifyCharacteristic, false); mNotifyCharacteristic = null; } } }
From source file:com.cypress.cysmart.BLEServiceFragments.HealthTemperatureService.java
/** * Preparing Broadcast receiver to broadcast notify characteristics * * @param gattCharacteristic/*from w w w . j av a2s. c o m*/ */ void prepareBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { mNotifyCharacteristic = gattCharacteristic; BluetoothLeService.setCharacteristicIndication(gattCharacteristic, true); } }
From source file:com.megster.cordova.ble.central.Peripheral.java
private void registerNotifyCallback(CallbackContext callbackContext, UUID serviceUUID, UUID characteristicUUID) { boolean success = false; if (gatt == null) { callbackContext.error("BluetoothGatt is null"); return;//from w ww. j a v a 2s .co m } BluetoothGattService service = gatt.getService(serviceUUID); BluetoothGattCharacteristic characteristic = findNotifyCharacteristic(service, characteristicUUID); String key = generateHashKey(serviceUUID, characteristic); if (characteristic != null) { notificationCallbacks.put(key, callbackContext); if (gatt.setCharacteristicNotification(characteristic, true)) { // Why doesn't setCharacteristicNotification write the descriptor? BluetoothGattDescriptor descriptor = characteristic .getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID); if (descriptor != null) { // prefer notify over indicate if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); } else { LOG.w(TAG, "Characteristic " + characteristicUUID + " does not have NOTIFY or INDICATE property set"); } if (gatt.writeDescriptor(descriptor)) { success = true; } else { callbackContext.error( "Failed to set client characteristic notification for " + characteristicUUID); } } else { callbackContext.error("Set notification failed for " + characteristicUUID); } } else { callbackContext.error("Failed to register notification for " + characteristicUUID); } } else { callbackContext.error("Characteristic " + characteristicUUID + " not found"); } if (!success) { commandCompleted(); } }
From source file:com.cypress.cysmart.BLEServiceFragments.BloodPressureService.java
/** * Preparing Broadcast receiver to broadcast indicate characteristics * * @param gattCharacteristic//w ww. j a v a 2s.co m */ void prepareBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { if (mIndicateCharacteristic != null) { mIndicateCharacteristic = gattCharacteristic; BluetoothLeService.setCharacteristicIndication(mIndicateCharacteristic, true); } } }
From source file:com.cypress.cysmart.BLEServiceFragments.BloodPressureService.java
/** * Stopping Broadcast receiver to broadcast indicate characteristics * * @param gattCharacteristic/* ww w .j a va 2 s.com*/ */ void stopBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { if (mIndicateCharacteristic != null) { Logger.d("Stopped notification"); BluetoothLeService.setCharacteristicIndication(mIndicateCharacteristic, false); mIndicateCharacteristic = null; } } }
From source file:ti.android.ble.devicemonitor.ServiceView.java
private String getPropertyDescription(int prop) { String str = new String(); if ((prop & BluetoothGattCharacteristic.PROPERTY_READ) > 0) str += "R"; if ((prop & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) str += "W"; if ((prop & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) str += "N"; if ((prop & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) str += "I"; if ((prop & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0) str += "*"; if ((prop & BluetoothGattCharacteristic.PROPERTY_BROADCAST) > 0) str += "B"; if ((prop & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) > 0) str += "E"; if ((prop & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) > 0) str += "S"; return str;// ww w . j ava2 s . com }
From source file:com.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findNotifyCharacteristic(BluetoothGattService service, UUID characteristicUUID) { BluetoothGattCharacteristic characteristic = null; // Check for Notify first List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c;/*w w w .j a v a 2s .c om*/ break; } } if (characteristic != null) return characteristic; // If there wasn't Notify Characteristic, check for Indicate for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c; break; } } // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties if (characteristic == null) { characteristic = service.getCharacteristic(characteristicUUID); } return characteristic; }
From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorDetails.java
/** * Preparing Broadcast receiver to broadcast indicate characteristics * * @param gattCharacteristic/*from ww w .j a v a 2 s . c o m*/ */ void prepareBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) { Logger.i("Indicate called"); final BluetoothGattCharacteristic characteristic = gattCharacteristic; final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) { BluetoothLeService.setCharacteristicIndication(gattCharacteristic, true); } }