In my Android app I am using ActivityRecognition API, which works perfectly fine. Unfortunately it takes some time for AR to get the first fix, I guess it waits some Significant Motion in order to get first fix or long time in order to decide if activity is "still", no matter that I set 1000 ms as detectionIntervalMillis. Sounds fine, but not always the case - sometimes even if the phone is still AR updates activity only after Significant Motion and does not detect still.
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mGoogleApiClient, 1000, mPendingIntent);
Of course I could simply agree that default is "still", but I do not want to completely rely on AR API and don't want to lose some location fixes (AR API doesn't work on some devices properly if they don't have updated Google Play Services), thus I set a default something like "no_activity_detected".
In other words I would like to change my activity to "still" only in case if AR API detects it.
My code are almost the same with the code on developers.google and the examples on the stackoverflow, so that should not be an issue.
MainActivity.java
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(ActivityRecognition.API)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
@Override
public void onConnected(Bundle bundle) {
MyLog.d(TAG, "on Connect Google API");
Intent intent = new Intent(this, ActivityRecognitionIntentService.class); // my custom ARS class
mPendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mGoogleApiClient, 1000, mPendingIntent);
}
ActivityRecognitionIntentService.java:
@Override
protected void onHandleIntent(Intent intent) {
/// Getting probable activity and sending a Broadcast with the recognized activity
}
As the solutions I see the next options:
1) To write another Still Recognition Service which works until the first fix from AR API and default "no_activity_detected" is changed.
2) Somehow force AR API to give me an update even non-confident after 1000 ms, as I wrote in requestActivityUpdates. It will make sure that AR API works and I can rely on it.
Is there the better way to solve my problem?