コード例 #1
0
 private void displayGattServices(List<BluetoothGattService> gattServices) {
   if (gattServices == null || gattServices.isEmpty()) {
     LogTool.e(TAG, "No Gatt Services Found!");
     return;
   }
   for (BluetoothGattService gattService : gattServices) {
     List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
     LogTool.d(
         TAG,
         "Service UUID = 【"
             + gattService.getUuid()
             + "】, Characteristics Size = 【"
             + (gattCharacteristics == null ? 0 : gattCharacteristics.size())
             + "】");
     if (gattCharacteristics != null) {
       for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
         LogTool.i(TAG, " Characteristic UUID = 【" + gattCharacteristic.getUuid() + "】");
       }
     }
   }
 }
コード例 #2
0
 @Override
 public void onServicesDiscovered(BluetoothGatt gatt, int status) {
   super.onServicesDiscovered(gatt, status);
   LogTool.d(TAG, "on services discovered success ? " + (status == BluetoothGatt.GATT_SUCCESS));
   if (status == BluetoothGatt.GATT_SUCCESS) {
     displayGattServices(gatt.getServices());
     if (gatt.getServices() == null || gatt.getServices().isEmpty()) {
       LogTool.e(TAG, "No gatt service found!");
       onServicesDiscoveredFailed(gatt);
       return;
     }
     if (!checkCloudWatchServiceSupported(gatt)) {
       LogTool.e(TAG, "Clouder watch services does not support!");
       onServicesDiscoveredFailed(gatt);
       gatt.disconnect();
       return;
     }
     onServicesDiscoveredSuccess(gatt);
   } else {
     LogTool.e(TAG, "Can not found gatt services!");
     onServicesDiscoveredFailed(gatt);
   }
 }