#StackBounty: #android #google-fit Android: Google Fit not finding data sources for DataType.TYPE_LOCATION_SAMPLE

Bounty: 100

I have some code that has worked for months in production which suddenly has stopped working yesterday in all my apps.
I use Google Fit to retrieve locations via the Fitness.SensorClient API.
Locations permissions are requested correctly to the user at installation time (both the generic Android FINE_LOCATION permission and the permission to read and store locations into Google Fit).
I create the Fitness Option in this way:

                    .addDataType(DataType.TYPE_LOCATION_SAMPLE, FitnessOptions.ACCESS_WRITE));

I then look for the DataSources in this way:

GoogleSignInAccount lastSignedAccount = GoogleSignIn.getAccountForExtension(context, getFitnessOptions());
    if (lastSignedAccount != null) {
        Fitness.getSensorsClient(context, lastSignedAccount)
                        new DataSourcesRequest.Builder()
                        new OnSuccessListener<List<DataSource>>() {
                            public void onSuccess(List<DataSource> dataSources) {
                                for (DataSource dataSource : dataSources) {
                                    Log.i(TAG, "Data source found: " + dataSource.toString());
                                    Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());

The value of the parameter dataSources in OnSuccessListener is an empty list. If I try other data types .setDataTypes(DataType.TYPE_STEP_COUNT_DELTA), dataSources is not an empty list. However neither DataType.TYPE_LOCATION_SAMPLE nor DataType.TYPE_LOCATION_TRACK return any data source.

I have checked the release notes of google services and nothing relevant seems to have changed.
The code above seems to be equivalent to all the examples provided by Google, e.g. this one

Does anyone have an idea of why suddenly that code has stopped working? Thanks

UPDATE: I have verified that it does not work with Android 6, 7, 8, or 9.

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.