ActivityRecognitionClient的活动识别无法解析,android中的错误

Mun*_*f M 2 performance android geolocation android-intent android-activity

我试图ActivityRecognition在android中使用来检测用户是否正在驾驶.

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

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

所以我手动导入com.google.android.gms.location.ActivityRecognitionClient;,但它也标记为红色,我已经安装了所有的谷歌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'
}
Run Code Online (Sandbox Code Playgroud)

ian*_*ake 5

根据Google Play Services 6.5要点:

不推荐使用的客户-的ActivityRecognitionClient,LocationClientPlusClient阶级已被弃用.如果您在应用中使用这些API并想要调用Google Play服务6.5或更高版本的API,则必须切换到使用GoogleApiClient的新编程模型.有关使用GoogleApiClient的详细信息,请参阅访问Google API.

使用这些API代替不推荐使用的API:

假设你有一个连接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());
        }
   }
});
Run Code Online (Sandbox Code Playgroud)