activity 的 ActivityRecognitionClient 识别无法解决,android 中的错误

ActivityRecognitionClient of activity Recognition cannot resolve ,error in android

我正在尝试在 android 中使用 ActivityRecognition 来检测用户是否在开车。

http://www.kpbird.com/2013/07/android-activityrecognition-example.html:这是我一直在尝试的示例代码...

但是当我写 ActivityRecognitionClient client; 时,我的 IDE(Android Studio) 说它无法解决它,并将其标记为红色,但 ActivityRecognition 已解决。

所以我手动导入了com.google.android.gms.location.ActivityRecognitionClient;,但它也被标记为红色,我已经安装了所有google Api和播放服务,

请帮我打通! :)

这是我的Gradle。

apply plugin: 'com.android.application'

android {
compileSdkVersion "Google Inc.:Google APIs:21"
buildToolsVersion "21.1.1"

defaultConfig {
    applicationId "interrupt.smart.com.smartinterrupt"
    minSdkVersion 16
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])


compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.google.android.gms:play-services:6.5.87'

compile 'com.google.android.gms:play-services-location:6.5.87'
}

根据 Google Play Services 6.5 highlights:

Deprecated clients - The ActivityRecognitionClient, LocationClient, and PlusClient classes are deprecated. If you used those APIs in your app and want to call Google Play services 6.5 or higher APIs, you must switch to the new programming model that utilizes GoogleApiClient. For more information about using GoogleApiClient, see Accessing Google APIs.

Use these APIs instead of the deprecated APIs:

假设您已连接 GoogleApiClient:

PendingResult<Status> result = ActivityRecognition.ActivityRecognitionApi
    .requestActivityUpdates(
        googleApiClient,         // your connected GoogleApiClient
        detectionIntervalMillis, // how often you want callbacks
        callbackIntent);         // the PendingIntent which will 
                                 //   receive updated activities

// Callback is asynchronous. Use await() on a background thread or listen for
// the ResultCallback
result.setResultCallback(new ResultCallback<Status>() {
    void onResult(Status status) {
        if (status.isSuccess()) {
            // Successfully registered
        } else if (status.hasResolution()) {
            // Google provides a way to fix the issue
            status.startResolutionForResult(
                activity,     // your current activity used to receive the result
                RESULT_CODE); // the result code you'll look for in your
                              // onActivityResult method to retry registering
        } else {
            // No recovery. Weep softly or inform the user.
            Log.e(TAG, "Registering failed: " + status.getStatusMessage());
        }
   }
});