0

나는 인텔 Fossil 안드로이드 기반의 Smartwatch (BLE 장치)에서 Google Fit Android SDK를 통해 데이터를 가져 오려고합니다. BLE 스캔이 발생하는 것처럼 보이지만 페어링이 발생하지만 결과 콜백 내에서 onDeviceFound로 이동하지 않습니다 (도달 할 경우 진행할 수 있습니다). 결국 스캔 시작부터 몇 초 내에 시간이 초과됩니다.스마트 시계에서 Google 피트니스 데이터를 얻는 방법 웨어러블 기기 Fossil Q 창업자? BLE 요구 사항을 준수합니까? 안드로이드에서

도움을 주시면 감사하겠습니다.

+0

이 발생할 코드 및 오류 로그를 공유 할 수 있습니까? [Bluetooth 센서 사용] (https://developers.google.com/fit/android/ble-sensors)에 대한 문서를 확인하여 사용자 데이터를 관리 할 때 적절한 구현 및 모범 사례를 검토하려면 [책임있는 사용 Google 피트니스] (https://developers.google.com/fit/overview#responsible_use_of_google_fit). 희망이 도움이됩니다! – KENdi

답변

0

docs 링크를 제공해 주셔서 감사합니다. 나는 그 모든 것을 철저히 통과했지만 도움이되지 못했습니다. 이것은 내 클래스 파일이며 MainActivity에서 startBleScan을 호출 할 수 있습니다. BleScan은 작동하는 것처럼 보이지만 이후에는 onDeviceFound 메소드로 진행하지 않습니다.

공용 클래스 BlueToothDevicesManager {

private static final String TAG = "BlueToothDevicesManager"; 
private static final int REQUEST_BLUETOOTH = 1001; 
private Main2Activity mMonitor; 
private GoogleApiClient mClient; 

public BlueToothDevicesManager(Main2Activity monitor, GoogleApiClient client) { 
    mMonitor = monitor; 
    mClient = client; 

} 

public void startBleScan() { 
    if (mClient.isConnected()) { 
     Log.i(TAG, "Google account is connected"); 
    } 
    BleScanCallback callback = new BleScanCallback() { 
     @Override 
     public void onDeviceFound(BleDevice device) { 
      Log.i(TAG, "BLE Device Found: " + device.getName()); 
      claimDevice(device); 
     } 

     @Override 
     public void onScanStopped() { 

      Log.i(TAG, "BLE scan stopped"); 
     } 
    }; 


    PendingResult result = Fitness.BleApi.startBleScan(mClient, new StartBleScanRequest.Builder() 
      .setDataTypes(DataType.TYPE_POWER_SAMPLE, DataType.TYPE_STEP_COUNT_CADENCE, DataType.TYPE_STEP_COUNT_DELTA, DataType.TYPE_SPEED, DataType.TYPE_ACTIVITY_SAMPLE, DataType.TYPE_DISTANCE_DELTA, DataType.TYPE_ACTIVITY_SEGMENT, DataType.TYPE_LOCATION_SAMPLE) 
      .setBleScanCallback(callback) 
      .build()); 

    result.setResultCallback(new ResultCallback() { 
     @Override 
     public void onResult(@NonNull Result result) { 
      Status status = result.getStatus(); 
      if (!status.isSuccess()) { 
       String a = status.getStatusCode() + ""; 
       Log.i(TAG, a); 
       switch (status.getStatusCode()) { 

        case FitnessStatusCodes.DISABLED_BLUETOOTH: 
         try { 

          status.startResolutionForResult(mMonitor, REQUEST_BLUETOOTH); 

         } catch (SendIntentException e) { 
          Log.i(TAG, "SendIntentException: " + e.getMessage()); 
         } 
         break; 
       } 
       Log.i(TAG, "BLE scan unsuccessful"); 
      } else { 
       Log.i(TAG, "ble scan status message: " + status.getStatusMessage()); 
       Log.i(TAG, "Ble scan successful: " + status.getResolution()); 


      } 
     } 
    }); 
} 

public void claimDevice(BleDevice device) { 
    //Stop ble scan 

    //Claim device 
    PendingResult<Status> pendingResult = Fitness.BleApi.claimBleDevice(mClient, device); 
    pendingResult.setResultCallback(new ResultCallback<Status>() { 

     @Override 
     public void onResult(@NonNull Status st) { 
      if (st.isSuccess()) { 
       Log.i(TAG, "Claimed device successfully"); 
      } else { 
       Log.e(TAG, "Did not successfully claim device"); 
      } 
     } 
    }); 
} 

}