List of usage examples for android.bluetooth BluetoothGattCharacteristic getProperties
public int getProperties()
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
/** * Stopping Broadcast receiver to broadcast notify characteristics * * @param gattCharacteristic// w ww .ja v a 2 s. co m */ void stopBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) { final BluetoothGattCharacteristic characteristic = gattCharacteristic; final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { if (mNotifyCharacteristic != null) { BluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false); } } }
From source file:com.ucai.test.control.DeviceControlActivity.java
/** * GATT?,?// w w w . java2 s . c om * ?? * http://d.android.com/reference/android/bluetooth/BluetoothGatt.html * ?? */ /* private final ExpandableListView.OnChildClickListener servicesListClickListner = new ExpandableListView.OnChildClickListener() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @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; } };*/ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void autoGetTemperature() { int groupPosition = 0; int childPosition = 0; Log.e("cst", "autoGetTemperature,mDeviceName=" + mDeviceName); if (SampleGattAttributes.DEVICE_NAME_TEMPERATURE.equals(mDeviceName)) { groupPosition = 2; childPosition = 2; mDeviceDataName.setText(R.string.device_temperature); } else if (SampleGattAttributes.DEVICE_NAME_WEIGHT.equals(mDeviceName)) { groupPosition = 1; childPosition = 0; mDeviceDataName.setText(R.string.device_weight); } else if (SampleGattAttributes.DEVICE_NAME_YUNMAI_WEIGHT.equals(mDeviceName)) { groupPosition = 2; childPosition = 0; mDeviceDataName.setText(R.string.device_weight); } else { return; } if (mGattCharacteristics != null) { final BluetoothGattCharacteristic characteristic = mGattCharacteristics.get(groupPosition) .get(childPosition); final int charaProp = characteristic.getProperties(); Log.e("cst", "autoGetTemperature,groupPosition=" + groupPosition + ",childPosition=" + childPosition + ",charaProp=" + charaProp + ",PROPERTY_READ=" + BluetoothGattCharacteristic.PROPERTY_READ + ",PROPERTY_NOTIFY=" + BluetoothGattCharacteristic.PROPERTY_NOTIFY); 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; } Log.e("cst", "autoGetTemperature,readCharacteristic(" + characteristic + ")"); mBluetoothLeService.readCharacteristic(characteristic); // Log.e("cst", "OnChildClickListener,setCharacteristicNotification("+characteristic+",true)"); // mBluetoothLeService.setCharacteristicNotification(characteristic,true); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; mBluetoothLeService.setCharacteristicNotification(characteristic, true); } } }
From source file:net.kenevans.android.blecardiacmonitor.BCMBleService.java
/** * Writes READ, NOTIFY, WRITE properties to the Log. Use for debugging. * * @param charBat The BAT characteristic. * @param charHr The HR characteristic. * @param charCustom The custom characteristic. *//*from www . ja v a2s . c o m*/ @SuppressWarnings("unused") public void checkPermissions(BluetoothGattCharacteristic charBat, BluetoothGattCharacteristic charHr, BluetoothGattCharacteristic charCustom) { // DEBUG // Check permissions if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charBat: Readable"); } if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charBat: Notifiable"); } if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Writable"); } else { Log.d(TAG, "incrementSessionState: charBat: Writable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charHr: Readable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charHr: Notifiable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Writable"); } else { Log.d(TAG, "incrementSessionState: charHr: Writable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Readable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Notifiable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Writable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Writable"); } }
From source file:com.cypress.cysmart.BLEServiceFragments.BatteryInformationService.java
/** * Method to get required characteristics from service *///from ww w. ja va 2s . c o m void getGattData() { List<BluetoothGattCharacteristic> gattCharacteristics = mService.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.BATTERY_LEVEL)) { mReadCharacteristic = gattCharacteristic; mNotifyCharacteristic = gattCharacteristic; /** * Checking the various GattCharacteristics and listing in the ListView */ if (checkCharacteristicsPropertyPresence(gattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_READ)) { mReadButton.setVisibility(View.VISIBLE); } if (checkCharacteristicsPropertyPresence(gattCharacteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_NOTIFY)) { mNotifyButton.setVisibility(View.VISIBLE); } prepareBroadcastDataRead(gattCharacteristic); break; } } }
From source file:net.kenevans.android.hxmmonitor.HxMBleService.java
/** * Writes READ, NOTIFY, WRITE properties to the Log. Use for debugging. * //from w w w . j a v a2 s. c om * @param charBat * @param charHr * @param charCustom */ public void checkPermissions(BluetoothGattCharacteristic charBat, BluetoothGattCharacteristic charHr, BluetoothGattCharacteristic charCustom) { // DEBUG // Check permissions if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charBat: Readable"); } if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charBat: Notifiable"); } if ((charBat.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charBat: Not Writeable"); } else { Log.d(TAG, "incrementSessionState: charBat: Writeable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charHr: Readable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charHr: Notifiable"); } if ((charHr.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charHr: Not Writeable"); } else { Log.d(TAG, "incrementSessionState: charHr: Writeable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Readable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Readable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Notifiable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Notifiable"); } if ((charCustom.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0) { Log.d(TAG, "incrementSessionState: charCustom: Not Writeable"); } else { Log.d(TAG, "incrementSessionState: charCustom: Writeable"); } }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
private void sendGattBroadcast(String address, String gattAction, BluetoothGattCharacteristic characteristic) { if (DEBUG)// w ww. j a v a2 s. com Log.d(TAG, "Sending the action: " + gattAction); Intent newIntent = BleEvents.createIntent(gattAction, address); if (characteristic != null) { newIntent.putExtra(UUID, characteristic.getUuid().toString()); newIntent.putExtra(FLAGS, characteristic.getProperties()); newIntent.putExtra(DATA, characteristic.getValue()); } LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent); }
From source file:com.example.android.bluetoothlegatt.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else {//w w w .j av a 2 s . co m format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); Log.d(TAG, String.format("Received heart rate: %d", heartRate)); intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); } else { // For all other profiles, writes the data formatted in HEX. final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { //// print data received. final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) stringBuilder.append(String.format("%02X ", byteChar)); //Log.i(TAG, "windsome1:"+ stringBuilder.toString()); //Log.i(TAG, "windsome2:"+ new String(data)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); //// write to file. long currTime = System.currentTimeMillis(); /*if ((currTime - cacheTime) > 500) { Log.i(TAG, "write cache to file! currTime="+currTime+", cacheTime="+cacheTime+", interval="+(currTime - cacheTime)); boolean isSame = writeCacheToFile2 (); cacheData2.clear(); intent.putExtra(EXTRA_DATA_SAME, isSame); }*/ cacheData2.add(data); cacheTime = currTime; mToastHandler.removeCallbacks(mRunnable); mToastHandler.postDelayed(mRunnable, 300); } } sendBroadcast(intent); }
From source file:com.qi.airstat.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); int signal = 0; // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else {//from ww w . ja v a 2s.c o m format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); signal = heartRate; Log.d(TAG, String.format("Received heart rate: %d", heartRate)); intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); } else { // For all other profiles, writes the data formatted in HEX. final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) stringBuilder.append(String.format("%02X ", byteChar)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); signal = Integer.parseInt(new String(data)); } } DatabaseManager databaseManager = new DatabaseManager(BluetoothLeService.this); SQLiteDatabase database = databaseManager.getWritableDatabase(); ContentValues values = new ContentValues(); String date = new SimpleDateFormat("yyMMddHHmmss").format(new java.util.Date()); values.put(Constants.DATABASE_COMMON_COLUMN_TIME_STAMP, date); values.put(Constants.DATABASE_HEART_RATE_COLUMN_HEART_RATE, signal); database.insert(Constants.DATABASE_HEART_RATE_TABLE, null, values); database.close(); try { Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); latitude = location.getLatitude(); longitude = location.getLongitude(); } catch (SecurityException exception) { exception.printStackTrace(); } JSONObject reformedObject = new JSONObject(); JSONArray reformedArray = new JSONArray(); try { JSONObject item = new JSONObject(); item.put("timeStamp", date); item.put("connectionID", Constants.CID_BLE); item.put("heartrate", signal); item.put("latitude", latitude); item.put("longitude", longitude); reformedArray.put(item); reformedObject.put("HR", reformedArray); } catch (JSONException e) { e.printStackTrace(); } HttpService httpService = new HttpService(); String responseCode = httpService.executeConn(null, "POST", "http://teamc-iot.calit2.net/IOT/public/rcv_json_data", reformedObject); sendBroadcast(intent); }
From source file:org.bcsphere.bluetooth.BluetoothG43plus.java
@Override public void setNotification(JSONArray json, CallbackContext callbackContext) { Log.i(TAG, "setNotification"); String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS); if (connectedDevice.get(deviceAddress) == null) { Tools.sendErrorMsg(callbackContext); return;/*ww w. j a v a 2 s .c o m*/ } int serviceIndex = Integer.parseInt(Tools.getData(json, Tools.SERVICE_INDEX)); int characteristicIndex = Integer.parseInt(Tools.getData(json, Tools.CHARACTERISTIC_INDEX)); String enable = Tools.getData(json, Tools.ENABLE); BluetoothGattCharacteristic characteristic = deviceServices.get(deviceAddress).get(serviceIndex) .getCharacteristics().get(characteristicIndex); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(Tools.NOTIFICATION_UUID); if (enable.equals("true")) { setNotificationCC.put(characteristic, callbackContext); if (Tools.lookup(characteristic.getProperties(), BluetoothGattCharacteristic.PROPERTY_NOTIFY) != null) { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); } else { descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); } mBluetoothGatts.get(deviceAddress).writeDescriptor(descriptor); mBluetoothGatts.get(deviceAddress).setCharacteristicNotification(characteristic, true); recordServiceIndex.put(characteristic, serviceIndex); recordCharacteristicIndex.put(characteristic, characteristicIndex); } else { descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); mBluetoothGatts.get(deviceAddress).writeDescriptor(descriptor); mBluetoothGatts.get(deviceAddress).setCharacteristicNotification(characteristic, false); Tools.sendSuccessMsg(callbackContext); setNotificationCC.remove(characteristic); recordServiceIndex.remove(characteristic); recordCharacteristicIndex.remove(characteristic); } }
From source file:com.muggins.test.ble.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/*ww w. java2 s . com*/ String uuid = null; // String unknownServiceString = getResources().getString(R.string.unknown_service); // String unknownCharaString = getResources().getString(R.string.unknown_characteristic); ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>(); mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, String> currentServiceData = new HashMap<String, String>(); if (SampleGattAttributes.SERVICE_NUMBER.equals(gattService.getUuid().toString())) { uuid = gattService.getUuid().toString(); // currentServiceData.put(LIST_NAME, "?"); // currentServiceData.put(LIST_UUID, "??1234"); // gattServiceData.add(currentServiceData); ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>(); List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { charas.add(gattCharacteristic); HashMap<String, String> currentCharaData = new HashMap<String, String>(); if (SampleGattAttributes.HEART_RATE_MEASUREMENT .equals(gattCharacteristic.getUuid().toString())) { uuid = gattCharacteristic.getUuid().toString(); currentCharaData.put(LIST_NAME, "?"); currentCharaData.put(LIST_UUID, ""); gattCharacteristicGroupData.add(currentCharaData); final int charaProp = gattCharacteristic.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. Log.e("BluetoothLeService", "read"); if (mNotifyCharacteristic != null) { mBluetoothLeService.setCharacteristicNotification( // mNotifyCharacteristic, false); mNotifyCharacteristic, true); mNotifyCharacteristic = null; } mBluetoothLeService.readCharacteristic(gattCharacteristic); // Intent intent = new Intent(DeviceControlActivity.this, ShowWave.class); // startActivity(intent); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { Log.e("BluetoothLeService", "notify"); mNotifyCharacteristic = gattCharacteristic; mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); } } } mGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } } SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(this, gattServiceData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }, gattCharacteristicData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }); mGattServicesList.setAdapter(gattServiceAdapter); }