Im trying to use Google Activity Recognition API, and get only results when activity changes or about every 30mins (+- 10mins or more if Activity does not change). Instead, when I call the piece of code below, I get Activity Recognition results very often in my IntentService
, like every minute:
ActivityRecognition
.ActivityRecognitionApi
.requestActivityUpdates(mGoogleApiClient, 60000 * 30, getSensingServicePendingIntent())
.setResultCallback(this);
The method to create PendingIntent
object:
private PendingIntent getSensingServicePendingIntent(Integer userLabel) {
Intent i = new Intent(mContext, SenseDataIntentService.class);
return PendingIntent
.getService(mContext, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
}
The method to getGoogleApiClient
:
private GoogleApiClient buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addApi(ActivityRecognition.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
return mGoogleApiClient;
}
I know that the official documentation says this:
Activities may be received more frequently than the detectionIntervalMillis parameter if another application has also requested activity updates at a faster rate. It may also receive updates faster when the activity detection service receives a signal that the current activity may change, such as if the device has been still for a long period of time and is then unplugged from a phone charger.
But I just think that I get the updates too frequently (even if activity does not change). Any solutions, as I want to save some battery drainage.