android - How to get users location bounding box from google fit api -
i'm trying users step count , location bounding box in last 24 hours google fit api.
i don't have problem step count i'm getting error location.
code:
@override protected void onstart() { super.onstart(); if (mgoogleapiclient == null) { mgoogleapiclient = new googleapiclient.builder(this) // optionally, add additional apis , scopes if required. .addapi(fitness.api) .addscope(new scope(scopes.fitness_location_read)) .addscope(new scope(scopes.fitness_activity_read)) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build(); } mgoogleapiclient.connect(); } private class getfitnesstask extends asynctask<void, void, string> { @override protected string doinbackground(void... params) { log.e("getfitnesstask", "getfitnesstask"); getstepstoday(); getlocation(); return null; } @override protected void onpostexecute(string s) { } } private void getstepstoday() { calendar cal = calendar.getinstance(); date = new date(); cal.settime(now); long endtime = cal.gettimeinmillis(); cal.set(calendar.hour_of_day, 0); cal.set(calendar.minute, 0); cal.set(calendar.second, 0); long starttime = cal.gettimeinmillis(); final datareadrequest readrequest = new datareadrequest.builder() .read(datatype.type_step_count_delta) .settimerange(starttime, endtime, timeunit.milliseconds) .build(); datareadresult datareadresult = fitness.historyapi.readdata(mgoogleapiclient, readrequest).await(1, timeunit.minutes); dataset stepdata = datareadresult.getdataset(datatype.type_step_count_delta); int totalsteps = 0; (datapoint dp : stepdata.getdatapoints()) { for(field field : dp.getdatatype().getfields()) { int steps = dp.getvalue(field).asint(); totalsteps += steps; } } log.e("fitnes", "total steps: " + totalsteps); } private void getlocation() { calendar cal = calendar.getinstance(); date = new date(); cal.settime(now); long endtime = cal.gettimeinmillis(); cal.set(calendar.hour_of_day, 0); cal.set(calendar.minute, 0); cal.set(calendar.second, 0); long starttime = cal.gettimeinmillis(); final datareadrequest readrequest = new datareadrequest.builder() .read(datatype.type_step_count_delta) .settimerange(starttime, endtime, timeunit.milliseconds) .build(); datareadresult datareadresult = fitness.historyapi.readdata(mgoogleapiclient, readrequest).await(1, timeunit.minutes); dataset locationdata = datareadresult.getdataset(datatype.aggregate_location_bounding_box); log.e("fit", locationdata.tostring()); int totalsteps = 0; (datapoint dp : locationdata.getdatapoints()) { for(field field : dp.getdatatype().getfields()) { log.e("fitnes", field.tostring()); } } }
i erorr in this:
dataset locationdata = datareadresult.getdataset(datatype.aggregate_location_bounding_box);
caused by: java.lang.illegalargumentexception: attempting read data com.google.location.bounding_box, not requested
so missing? how can location bounding box? thanks
Comments
Post a Comment