My app reads weight data from Google Fit. The data was inserted by Withings and my own application. But that doesn't make any difference when I call dataSet.getDataSource().getAppPackageName() because it always returns com.google.android.gms . Therefore, I have no chance of knowing where the data came from. Google describes how to get information about the data source in this article: https://developers.google.com/fit/android/data-attribution Unfortunately, this is completely useless to me.
I am using Google Play Services 8.3.0, tested with Android 4.3, 4.4.2 and 6.0.1.
Can anyone confirm the same behavior? Or am I doing something wrong? Any feedback is welcome.
public void connect(final Activity activity) { client = new GoogleApiClient.Builder(activity) .addApi(Fitness.HISTORY_API) .addApi(Fitness.CONFIG_API) .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE)) .addScope(new Scope(Scopes.FITNESS_BODY_READ_WRITE)) .build(); client.connect(); } public DataReadResult readWeightValues(final Date startDate, final Date endDate) { final DataReadRequest readRequest = new DataReadRequest.Builder() .enableServerQueries() .setTimeRange(startDate.getTime(), endDate.getTime(), TimeUnit.MILLISECONDS) .read(DataType.TYPE_WEIGHT) .build(); return Fitness.HistoryApi.readData(client, readRequest).await(1, TimeUnit.MINUTES); } public void examineWeightValues(final DataReadResult dataReadResult) { if ((dataReadResult != null) && dataReadResult.getStatus().isSuccess()) { if (!dataReadResult.getBuckets().isEmpty()) { for (final Bucket bucket : dataReadResult.getBuckets()) { final List<DataSet> dataSets = bucket.getDataSets(); for (final DataSet dataSet : dataSets) { Log.i("=====>", dataSet.getDataSource().getAppPackageName()); } } } if (!dataReadResult.getDataSets().isEmpty()) { for (final DataSet dataSet : dataReadResult.getDataSets()) { Log.i("=====>", dataSet.getDataSource().getAppPackageName()); } } } } public Status insertWeightValue(final Context context, final Date date, final float weightKg) { final DataSource dataSource = new DataSource.Builder() .setAppPackageName(context.getApplicationContext().getPackageName())
android google-play-services google-fit google-fit-sdk
stefan222
source share