I want to request sensor data from my mi band 2 using my android app in real time. I have some difficulties with this. I use permissions BLUETOOTH
and BLUETOOTH_ADMIN
. I checked that I can see my device via Bluetooth le default API.
I am trying to use this example https://developers.google.com/fit/android/ble-sensors?hl=ru and all the time I get onScanStopped and this callback don't have some explanation, so I don't understand why it fails.
My code:
GoogleApiClient client = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
.addScope(new Scope(Scopes.FITNESS_BODY_READ))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
client.connect();
And onConnected I have:
Fitness.getBleClient(this, GoogleSignIn.getLastSignedInAccount(this))
.startBleScan(Arrays.asList(DataType.TYPE_ACTIVITY_SEGMENT), 60, bleScanCallbacks)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d("TAG_F", "onComplete: " + task.isSuccessful());
}
});
Here I also tried all of this data types DataType.TYPE_STEP_COUNT_DELTA, DataType.TYPE_HEART_RATE_BPM
This shows me that my scan is successful. But on callback after 60 seconds I get onScanStopped
:
private BleScanCallback bleScanCallbacks = new BleScanCallback() {
@Override
public void onDeviceFound(BleDevice bleDevice) {
Log.d("TAG_F", "onDeviceFound: " + bleDevice.getDataTypes());
}
@Override
public void onScanStopped() {
Log.d("TAG_F", "onScanStopped: ");
}
};