0

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.

urgas9
  • 806
  • 9
  • 22
  • possible duplicate: http://stackoverflow.com/questions/27500602/android-activityrecognitionapi-requestactivityupdates-are-too-frequent-how-can – Android Enthusiast Feb 08 '16 at 01:27

1 Answers1

0

I think I have figured that out. Google Fit was running in the background and it was constantly listening to activity changes. Therefore, I got all those results as well (as it is written in the documentation).

urgas9
  • 806
  • 9
  • 22