android - How to properly retrieve package name of the app that inserted data to Google Fit? -
i have following code using retrieve list of user's activities google fit:
public void getactivitiesdata(date from, date till) { datareadrequest readrequest = new datareadrequest.builder() .aggregate(datatype.type_activity_segment, datatype.aggregate_activity_summary) .bucketbytime(1, timeunit.days) .settimerange(from.gettime(), till.gettime(), timeunit.milliseconds) .build(); fitness.historyapi.readdata(apiclient, readrequest).setresultcallback(new com.google.android.gms.common.api.resultcallback<datareadresult>() { @override public void onresult(datareadresult datareadresult) { status status = datareadresult.getstatus(); if (status.issuccess()) { (bucket bucket : datareadresult.getbuckets()) { if (!bucket.getdatasets().isempty()) { dataset dataset = bucket.getdatasets().get(0); string sourceapppackagename = getsourceapppackagenamefromdataset(dataset); (datapoint dp : dataset.getdatapoints()) { (field field : dp.getdatatype().getfields()) { string fieldname = field.getname(); if (fieldname != null && fieldname.equals("activity")) { string type = fitnessactivities.getvalue(dp); date = new date(dp.getstarttime(timeunit.milliseconds)); date till = new date(dp.getendtime(timeunit.milliseconds)); // store retrieved values data object, omitted } } } } } } } }); } private static string getsourceapppackagenamefromdataset(dataset dataset) { string result = null; if (dataset.getdatasource() != null) { result = dataset.getdatasource().getapppackagename(); } return result; }
to insert activities google fit, i've used google fit app , runkeeper (right now, these apps seem ones integrated fit).
my code retrieves these activities expected, however, each activity, getsourceapppackagenamefromdataset()
method returns "com.google.android.gms"
package name. per data attribution section in google fit documentation, expect method return package name of either runkeeper or google fit, not happen.
am doing horribly wrong, or bug in google fit?
datapoint.getoriginaldatasource().getapppackagename()
trick. returns com.withings.wiscale2
withings scale, while dataset.getdatasource().getapppackagename()
always returns com.google.android.gms
.
there's similar question right here: datasource.getapppackagename() returns "com.google.android.gms" in google fit
Comments
Post a Comment