my Android App needs to detect the current Activity (running, walking, ...).
I followed the instructions on the Android Dev Page: http://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionClient.html
// Connect to the ActivityRecognitionService
ActivityRecognitionClient mActivityRecognitionClient =
new ActivityRecognitionClient(this, this, this);
mActivityRecognitionClient.connect();
// Called when a connection to the ActivityRecognitionService has been established.
public void onConnected(Bundle connectionHint) {
Intent intent = new Intent(this, MyIntentService.class);
PendingIntent callbackIntent = PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
mActivityRecognitionClient.requestActivityUpdates(30000, callbackIntent);
}
And in my Intent-Service:
protected void onHandleIntent(Intent intent) {
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
// Put your application specific logic here (i.e. result.getMostProbableActivity())
}
}
Here's my problem: I want to start the activity recognition on my own. The Code from the Android Dev Page seems, like it's supposed to do that. BUT if I don't add the service to the AndroidManifest, it won't do anything. The onConnected() method gets called, but not onHandleIntent().
So I thought I might just need to add it to the Manifest. Now I do receive Activities, but I receive them all the time. This is also not what I want. What am I doing wrong?
Thanks in advance, Steff