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)
                    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ))
                    .addScope(new Scope(Scopes.FITNESS_BODY_READ))

And onConnected I have:

Fitness.getBleClient(this, GoogleSignIn.getLastSignedInAccount(this))
.startBleScan(Arrays.asList(DataType.TYPE_ACTIVITY_SEGMENT), 60, bleScanCallbacks)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            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() {
        public void onDeviceFound(BleDevice bleDevice) {
            Log.d("TAG_F", "onDeviceFound: " + bleDevice.getDataTypes());


        public void onScanStopped() {
            Log.d("TAG_F", "onScanStopped: ");

1 Answers

Andrea Scalabrini On

onScanStopped() is called when the timeout specified in

startBleScan(List<DataType> dataTypes, int timeoutSecs, BleScanCallback callback)


Try to increase/decrease the time (60') specified in your method:

 Fitness.getBleClient(this, GoogleSignIn.getLastSignedInAccount(this))
    .startBleScan(Arrays.asList(DataType.TYPE_ACTIVITY_SEGMENT), 60, bleScanCallbacks)

Android Documentation