List of usage examples for android.bluetooth BluetoothGattService getCharacteristics
public List<BluetoothGattCharacteristic> getCharacteristics()
From source file:com.junkchen.blelib.sample.BleScanActivity.java
private void setBleServiceListener() { mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { @Override/*from w w w. j a v a 2 s . c o m*/ public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServiceList = gatt.getServices(); characteristicList = new ArrayList<>(); serviceList.clear(); for (BluetoothGattService service : gattServiceList) { String serviceUuid = service.getUuid().toString(); serviceList.add(MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); Log.i(TAG, MyGattAttributes.lookup(serviceUuid, "Unknown") + "\n" + serviceUuid); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); String[] charArra = new String[characteristics.size()]; for (int i = 0; i < characteristics.size(); i++) { String charUuid = characteristics.get(i).getUuid().toString(); charArra[i] = MyGattAttributes.lookup(charUuid, "Unknown") + "\n" + charUuid; } characteristicList.add(charArra); } mHandler.sendEmptyMessage(SERVICE_SHOW); } } }); // //Ble?? // mBleService.setOnLeScanListener(new BleService.OnLeScanListener() { // @Override // public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { // //???Ble????? // } // }); // //Ble // mBleService.setOnConnectListener(new BleService.OnConnectListener() { // @Override // public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { // if (newState == BluetoothProfile.STATE_DISCONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTING) { // //Ble // } else if (newState == BluetoothProfile.STATE_CONNECTED) { // //Ble // } else if (newState == BluetoothProfile.STATE_DISCONNECTING) { // //Ble // } // } // }); // //Ble?? // mBleService.setOnServicesDiscoveredListener(new BleService.OnServicesDiscoveredListener() { // @Override // public void onServicesDiscovered(BluetoothGatt gatt, int status) { // // } // }); // //Ble? // mBleService.setOnDataAvailableListener(new BleService.OnDataAvailableListener() { // @Override // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { // //??? // } // // @Override // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // //?? // } // @Override // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { // // } // }); mBleService.setOnReadRemoteRssiListener(new BleService.OnReadRemoteRssiListener() { @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { Log.i(TAG, "onReadRemoteRssi: rssi = " + rssi); } }); }
From source file:com.example.android.bluetoothlegatt.DeviceControlActivity.java
private boolean bluetoothLookup(BluetoothGattService gattService, String readCharacteristicUuid, String writeCharacteristicUuid, String notifyCharacteristicUuid) { for (BluetoothGattCharacteristic characteristic : gattService.getCharacteristics()) { final String uuid = characteristic.getUuid().toString(); Log.d(TAG,/*from w w w . j a v a 2 s . c om*/ "characteristic " + uuid.substring(4, 8) + ": " + Util.isCharacteristicReadable(characteristic) + " " + Util.isCharacteristicWritable(characteristic) + " " + Util.isCharacteristicNotifiable(characteristic)); if (uuid.toString().equalsIgnoreCase(readCharacteristicUuid) && Util.isCharacteristicReadable(characteristic)) { Log.d(TAG, "Setup characteristic read " + uuid.substring(4, 8)); mReadCharacteristic = characteristic; // 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; } } if (uuid.toString().equalsIgnoreCase((writeCharacteristicUuid)) && Util.isCharacteristicWritable(characteristic)) { Log.d(TAG, "Setup characteristic write " + uuid.substring(4, 8)); mWriteCharacteristic = characteristic; } if (uuid.toString().equalsIgnoreCase(notifyCharacteristicUuid) && Util.isCharacteristicNotifiable(characteristic)) { Log.d(TAG, "Setup characteristic notify " + uuid.substring(4, 8)); mNotifyCharacteristic = characteristic; mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, true); } } return (mReadCharacteristic != null && mWriteCharacteristic != null); }
From source file:com.mikroe.hexiwear_android.DeviceScanActivity.java
private void displayGattServices(List<List<BluetoothGattService>> devicesGattServices) { if (devicesGattServices == null) return;//from w ww . j a va 2s. c o m String uuid = null; ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>(); ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>(); ArrayList<ArrayList<BluetoothGattCharacteristic>> tempGattCharacteristics = new ArrayList<>(); mGattsCharacteristics.clear(); for (List<BluetoothGattService> gattServices : devicesGattServices) { // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { HashMap<String, String> currentServiceData = new HashMap<String, String>(); uuid = gattService.getUuid().toString(); 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(); if (uuid.equals(UUID_CHAR_ALERTIN)) { alertInCharacteristic = gattCharacteristic; byte[] value = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; alertInCharacteristic.setValue(value); } currentCharaData.put(LIST_UUID, uuid); gattCharacteristicGroupData.add(currentCharaData); } tempGattCharacteristics.add(charas); gattCharacteristicData.add(gattCharacteristicGroupData); } mGattsCharacteristics.add(tempGattCharacteristics); } mHandler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(DeviceScanActivity.this, MainScreenActivity.class); startActivity(intent); } }, 1500); }
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 www.ja va2 s. c o 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:undot.safedrivers.BLE.BluetoothLeService.java
private void getGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;// w w w . j av a 2s . c o m String uuid = null; mModelNumberCharacteristic = null; mSerialPortCharacteristic = null; mCommandCharacteristic = null; mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>(); // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { uuid = gattService.getUuid().toString(); System.out.println("displayGattServices + uuid=" + uuid); List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { charas.add(gattCharacteristic); uuid = gattCharacteristic.getUuid().toString(); if (uuid.equals(ModelNumberStringUUID)) { mModelNumberCharacteristic = gattCharacteristic; System.out.println( "mModelNumberCharacteristic " + mModelNumberCharacteristic.getUuid().toString()); } else if (uuid.equals(SerialPortUUID)) { mSerialPortCharacteristic = gattCharacteristic; System.out.println( "mSerialPortCharacteristic " + mSerialPortCharacteristic.getUuid().toString()); // updateConnectionState(R.string.comm_establish); } else if (uuid.equals(CommandUUID)) { mCommandCharacteristic = gattCharacteristic; System.out.println( "mSerialPortCharacteristic " + mSerialPortCharacteristic.getUuid().toString()); // updateConnectionState(R.string.comm_establish); } } mGattCharacteristics.add(charas); } if (mModelNumberCharacteristic == null || mSerialPortCharacteristic == null || mCommandCharacteristic == null) { Log.d("charactaristics", "null"); Toast.makeText(getApplicationContext(), "characteristics null", Toast.LENGTH_SHORT); } else { mSCharacteristic = mModelNumberCharacteristic; setCharacteristicNotification(mSCharacteristic, true); readCharacteristic(mSCharacteristic); } }
From source file:com.example.bluetoothlegatt.DeviceControlActivity.java
private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;/*from w w w . j av a2s . 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 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. 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:org.zpcat.ble.ui.central.DeviceControlActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void displayGattServices(List<BluetoothGattService> gattServices) { Log.d("displayGATTServices"); if (gattServices == null) return;/*from w ww. j ava 2s. 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.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findWritableCharacteristic(BluetoothGattService service, UUID characteristicUUID, int writeType) { BluetoothGattCharacteristic characteristic = null; // get write property int writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE; if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) { writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE; }/* w w w .j a v a2 s.co m*/ List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & writeProperty) != 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.example.ecgfile.DeviceControlActivity.java
@SuppressLint("SimpleDateFormat") private void getGattServices(List<BluetoothGattService> gattServices) { System.out.println("getGattServices"); if (gattServices == null) { System.out.println("getGattServices null "); return;/*from ww w . ja v a2 s.c o m*/ } String uuid = null; // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { uuid = gattService.getUuid().toString(); if (uuid.equals("0000ffe0-0000-1000-8000-00805f9b34fb") || uuid.equals("0000ffe5-0000-1000-8000-00805f9b34fb")) { // 2uuid service List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { charas.add(gattCharacteristic); uuid = gattCharacteristic.getUuid().toString(); if (uuid.equals("0000ffe4-0000-1000-8000-00805f9b34fb")) { mNotifyCharacteristic = gattCharacteristic; Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show(); } if (uuid.equals("0000ffe9-0000-1000-8000-00805f9b34fb")) { mNCharW = gattCharacteristic; } } } } }