2014-09-29 36 views
1

我跟着樣本代碼(https://developers.google.com/fit/android/ble-sensors),但我得到以下錯誤。如何使用Android Fit SDK掃描BLE設備?我得到和接口不匹配錯誤

private void buildFitnessClient() { 
    // Create the Google API Client 
    mClient = new GoogleApiClient.Builder(this) 
     .addApi(Fitness.API) 
     .addScope(FitnessScopes.SCOPE_ACTIVITY_READ) 
     .addScope(FitnessScopes.SCOPE_BODY_READ) 
     .addScope(FitnessScopes.SCOPE_LOCATION_READ) 
     .addConnectionCallbacks(
       new GoogleApiClient.ConnectionCallbacks() { 
        @Override 
        public void onConnected(Bundle bundle) { 
         Log.i(TAG, "Connected!!!"); 
         buildBle(); // Scan for BLE Devices. 
        } 

        @Override 
        public void onConnectionSuspended(int i) { 
         // .. 
        } 
       } 
     ) 
     .addOnConnectionFailedListener(
       new GoogleApiClient.OnConnectionFailedListener() { 
        // .. 
       } 
     ) 
     .build(); 
} 

private void buildBle() { 
    BleScanCallback callback = new BleScanCallback() { 
     @Override 
     public void onDeviceFound(BleDevice device) { 
      ClaimBleDeviceRequest request = new ClaimBleDeviceRequest.Builder() 
       .setDevice(device) 
       .build(); 
      PendingResult<Status> pendingResult = 
        Fitness.BleApi.claimBleDevice(mClient, request); 
     } 
     @Override 
     public void onScanStopped() { 
      // .. 
     } 
    }; 

    StartBleScanRequest request = new StartBleScanRequest.Builder() 
     .setDataTypes(DataTypes.HEART_RATE_BPM) 
     .setBleScanCallback(callback) 
     .build(); 

    PendingResult<Status> pendingResult = 
     Fitness.BleApi.startBleScan(mClient, request); 

} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // .. 
    buildFitnessClient(); 
} 

調用buildBle()方法給出了以下錯誤。

09-29 12:38:27.777: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:27.777: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:27.777: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:27.777: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:27.777: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:27.777: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:27.777: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:28.794: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:28.794: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:28.794: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:28.794: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:28.794: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:28.794: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:28.794: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:29.801: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:29.802: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:29.802: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:29.802: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:29.802: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:29.802: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:29.802: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:31.816: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:31.817: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:31.817: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:31.817: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:31.817: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:31.817: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:31.817: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:32.845: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:32.845: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:32.845: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:32.845: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:32.845: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:32.845: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:32.845: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:33.842: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:33.854: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:33.854: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:33.854: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:33.854: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:33.854: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:33.854: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:34.847: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:34.848: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:34.848: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:34.848: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:34.848: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:34.848: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:34.848: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:35.849: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:35.856: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:35.856: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:35.856: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:35.856: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:35.856: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:35.856: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 
09-29 12:38:36.275: W/Parcel(5900): **** enforceInterface() expected 'com.google.android.gms.fitness.ble.IBleScanCallback' but read 'com.google.android.gms.fitness.request.IBleScanCallback' 
09-29 12:38:36.276: W/Binder(5900): Caught a RuntimeException from the binder stub implementation. 
09-29 12:38:36.276: W/Binder(5900): java.lang.SecurityException: Binder invocation to an incorrect interface 
09-29 12:38:36.276: W/Binder(5900):  at android.os.Parcel.nativeEnforceInterface(Native Method) 
09-29 12:38:36.276: W/Binder(5900):  at android.os.Parcel.enforceInterface(Parcel.java:453) 
09-29 12:38:36.276: W/Binder(5900):  at com.google.android.gms.fitness.ble.d$a.onTransact(Unknown Source) 
09-29 12:38:36.276: W/Binder(5900):  at android.os.Binder.execTransact(Binder.java:404) 

請幫忙。謝謝。

回答

0

您應該在claimBleDevice調用中使用該設備。像這樣:

BleScanCallback callback = new BleScanCallback() { 
    @Override 
    public void onDeviceFound(BleDevice device) { 

     PendingResult<Status> pendingResult = 
       Fitness.BleApi.claimBleDevice(mClient, device); 
    } 
0

試試這個添加到GoogleApiClient建設者:

.addApi(Fitness.BLE_API) 
0

試試這個,

private BleScanCallback callback; 


private void buildBle() { 
     callback = new BleScanCallback() { 
      @Override 
      public void onDeviceFound(BleDevice device) { 
      // ClaimBleDeviceRequest request = new ClaimBleDeviceRequest(mClient,device); 

       PendingResult<Status> pendingResult = 
         Fitness.BleApi.claimBleDevice(mClient, device); 
      } 
      @Override 
      public void onScanStopped() { 

       // .. 
      } 
     }; 

     StartBleScanRequest request = new StartBleScanRequest.Builder() 
       .setDataTypes(DataType.TYPE_HEART_RATE_BPM) 
       .setBleScanCallback(callback) 
       .build(); 

     PendingResult<Status> pendingResult = 
       Fitness.BleApi.startBleScan(mClient, request); 

    }