List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid
public UUID getUuid()
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
/** * stop notifications of all Report characteristc *///from w w w. j a va 2s .co m private void stopBroadcastAllNotifications() { List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.REP0RT)) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { BluetoothLeService.setCharacteristicNotification(gattCharacteristic, false); } } } }
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
/** * Method to get all Characteristic with report reference *//*from w ww .ja v a 2 s. c o m*/ private void getAllCharacteristicReportReference() { List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics(); charaDataModel.clear(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.REP0RT)) { ReportCharacteristicDescriptionModel data = new ReportCharacteristicDescriptionModel( gattCharacteristic, gattCharacteristic.getInstanceId()); charaDataModel.add(data); } } prepareBroadcastAllNotifications(); }
From source file:com.chenls.smartlock.UartService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic, final int status) { final Intent intent = new Intent(action); if (RX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(WRITE_STATUS, "" + status); }/*from w w w. j av a 2s . c o m*/ LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.google.android.apps.forscience.ble.MyBleService.java
public void printServices(String address) { BluetoothGatt bluetoothGatt = addressToGattClient.get(address); if (bluetoothGatt == null) { Log.d(TAG, "No connection found for: " + address); return;/*from www . j a v a2 s .c o m*/ } for (BluetoothGattService service : bluetoothGatt.getServices()) { Log.d(TAG, "Service ================================"); Log.d(TAG, "Service UUID: " + service.getUuid()); Log.d(TAG, "Service Type: " + service.getType()); for (BluetoothGattCharacteristic charact : service.getCharacteristics()) { Log.d(TAG, "Charact UUID: " + charact.getUuid()); Log.d(TAG, "Charact prop: " + charact.getProperties()); if (charact.getValue() != null) { Log.d(TAG, "Charact Value: " + new String(charact.getValue())); } } } }
From source file:com.cypress.cysmart.BLEServiceFragments.RSCService.java
/** * Method to get required characteristics from service *//*from w w w . java2 s. com*/ void getGattData() { List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidCharacteristics = gattCharacteristic.getUuid().toString(); if (uuidCharacteristics.equalsIgnoreCase(GattAttributes.RSC_MEASUREMENT)) { mNotifyCharacteristic = gattCharacteristic; prepareBroadcastDataNotify(mNotifyCharacteristic); } } }
From source file:com.example.bluetoothlegatt.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;//from w w w . j a v a2 s. c om 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>(); uuid = gattService.getUuid().toString(); currentServiceData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString)); currentServiceData.put(LIST_UUID, uuid); 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>(); uuid = gattCharacteristic.getUuid().toString(); currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString)); currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } 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); }
From source file:com.touchKin.touchkinapp.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/* w ww .ja v a 2 s .c o m*/ 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>(); uuid = gattService.getUuid().toString(); currentServiceData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString)); currentServiceData.put(LIST_UUID, uuid); 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. characteristicTX = gattService .getCharacteristic(UUID.fromString("00001525-1212-efde-1523-785feabcd123")); characteristicRX = gattService .getCharacteristic(UUID.fromString("00001525-1212-efde-1523-785feabcd123")); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { charas.add(gattCharacteristic); HashMap<String, String> currentCharaData = new HashMap<String, String>(); uuid = gattCharacteristic.getUuid().toString(); currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString)); currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } 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); }
From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java
private boolean readCharacteristics(BluetoothGatt gatt) { if (null == gatt) return false; String deviceName = gatt.getDevice().getName(); List<BluetoothGattService> gattServices = gatt.getServices(); if (gattServices == null) return false; String unknownServiceString = getResources().getString(R.string.unknown_service); String unknownCharaString = getResources().getString(R.string.unknown_characteristic); // Find the device node from device-service-characteristic tree Node<String> deviceNode = null; for (Node<String> node : device_service_characteristicTree.getChildren()) { if (node.data.equals(deviceName)) { deviceNode = node;//from w ww . j a v a 2 s .co m break; } } // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { String serviceUuid = gattService.getUuid().toString(); String serviceName = SampleGattAttributes.lookup(serviceUuid, unknownServiceString); // Find desired service for (Node<String> serviceNode : deviceNode.getChildren()) { if (serviceName.equals(serviceNode.data)) { List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String characteristicUuid = gattCharacteristic.getUuid().toString(); String characteristicName = SampleGattAttributes.lookup(characteristicUuid, unknownCharaString); // Find desired characteristic of selected service for (Node<String> characteristicNode : serviceNode.getChildren()) { if (characteristicName.equals(characteristicNode.data)) { Log.i(null, "FOUND DESIRED characteristic!!!"); readCharacteristic(gatt, gattCharacteristic); break; } } } } } } return true; }
From source file:com.ble.BLService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); if (UUID_STM32_ACCELEROMETER_PARAMETER.equals(characteristic.getUuid())) { // una elaborazione dei dati inviati dalla scheda ST32 che invia i dati come un flusso di byte ad otetti //quindi converto in esadecimale e scambio i primi due ottetti per ottrenerli in ordine //0000-0000-0000-0000|acc_x_bit_meno_significativi[8byte]-acc_x_bit_significativi[8byte]|acc_y_meno..-acc_y..|acc_z_meno...-acc_ // in hex ogni 4 byte ho un valore //0-1-2-3|4-5-6-7|8-9-10-11|12-13-14-15 //per acc_x devo avere i blocchi 6-7-4-5 affiancati //per acc_y =10-11-8-9 //per acc_z=14-15-12-13 //acc_x=sb1.append(sb.substring(6, 8)) concatenato con sb1.append(sb.substring(4, 6)); //magari esiste un metodo meno contorto per recuperarli,io purtroppo non l'ho trovato :-( byte[] stream_byte_received = characteristic.getValue(); StringBuilder sb = new StringBuilder(); for (byte b : stream_byte_received) { sb.append(String.format("%02x", b)); }//from w w w. ja va2 s . com StringBuilder sb1 = new StringBuilder(); sb1.append(sb.substring(6, 8)); sb1.append(sb.substring(4, 6)); String test = sb1.toString(); short acc_x = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(10, 12)); sb1.append(sb.substring(8, 10)); test = sb1.toString(); short acc_y = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(14, 16)); sb1.append(sb.substring(12, 14)); test = sb1.toString(); short acc_z = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(18, 20)); sb1.append(sb.substring(16, 18)); test = sb1.toString(); short temperatura = (short) Integer.parseInt(test, 16); sb1 = new StringBuilder(); sb1.append(sb.substring(22, 24)); sb1.append(sb.substring(20, 22)); test = sb1.toString(); short Humidity = (short) Integer.parseInt(test, 16); //EVENTUALE SENSORE DA CATTURARE ESEMPIO TEMPERATURA,AFFIANCO NEL VETTORE GATT DEL DEVICE ST32 //16-17-18-19 //sbX.append(sb.substring(18));sbX.append(sb.substring(16, 18)); Log.w("ADC3", "StringBuilder " + sb + "************************** " + acc_x + " | " + acc_y + " | " + acc_z + " | "); String accelerometer = "|X:" + acc_x + " |Y: " + acc_y + " |Z: " + acc_z + " | "; String extra_data = "Temp:" + temperatura + "\nHumidity:" + Humidity + "%\nAccelerometer:\t" + accelerometer; intent.putExtra(EXTRA_DATA, extra_data); } else { 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()); } } sendBroadcast(intent); }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
private void storeCharacteristicsFromService(BluetoothGattService gattService) { for (BluetoothGattCharacteristic gattCharacteristic : gattService.getCharacteristics()) { final String characteristicUuid = gattCharacteristic.getUuid().toString(); final Characteristic characteristic = Characteristic.byUuid(characteristicUuid); if (characteristic == Characteristic.ALERT_IN) { Log.d(TAG, "ALERT_IN DISCOVERED"); alertIn = gattCharacteristic; setTime();//ww w . ja v a2 s . co m NotificationService_.intent(BluetoothService.this).start(); } else if (characteristic != null) { Log.v(TAG, characteristic.getType() + ": " + characteristic.name()); readableCharacteristics.put(characteristicUuid, gattCharacteristic); } else { Log.v(TAG, "UNKNOWN: " + characteristicUuid); } } }