0

I've tried a whole month to learn to use Google's Activity Recognition service, and met a very confusing problem while adding ActivityRecognition.API to mGoogleApiClient.

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(ActivityRecognition.API)
        .build(); 

I'm given an error which says "Cannot resolve symbol 'ActivityRecognition'". Then I imported anything that looks related with ActivityRecognition like,

import com.google.android.gms.location.ActivityRecognitionClient
import com.google.android.gms.location.ActivityRecognitionResult
import com.google.android.gms.location.ActivityRecognitionResultCreator
import com.google.android.gms.location.DetectedActivity

and nothing worked. I can't even find a person who encountered this situation. Also, the official document shows ActivityRecognition is not deprecated.

Here is my screenshot. (Please ignore the underline of 'this'. That has been solved, and I'm pretty sure it has nothing to do with the 'ActivityRecognition' error. )

I'm using Android Studio 1.3.2 on Windows7 x64. I don't know if this information is necessary.

Activity Recognition will surly help a lot on my developing app. Sincerely hope someone could help me.

icoder
  • 61
  • 2
  • 8

1 Answers1

1

Okay, I've successfully dealt with this problem. I think it's related to the version of Google Play Services.

I replaced my original version of 4.1.32 with a new version of 8.1.0, which I see in a Google's official example. If anyone face the same problem, go to gradle(module), in the field of dependencies, update your

compile 'com.google.android.gms:play-services:[version]'

to a higher version. Hope this will help.