【问题标题】:ActivityRecognitionClient of activity Recognition cannot resolve ,error in androidActivityRecognitionClient的Activity Recognition无法解析,android中的错误
【发布时间】:2015-01-10 06:02:29
【问题描述】:

我正在尝试在 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和playservices,

请帮助我度过难关! :)

这是我的 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'
}

【问题讨论】:

    标签: android performance android-intent android-activity geolocation


    【解决方案1】:

    根据Google Play Services 6.5 highlights

    已弃用的客户端 - ActivityRecognitionClientLocationClientPlusClient 类已弃用。如果您在应用程序中使用了这些 API,并且想要调用 Google Play 服务 6.5 或更高版本的 API,则必须切换到利用 GoogleApiClient 的新编程模型。有关使用GoogleApiClient 的更多信息,请参阅Accessing Google APIs

    使用这些 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());
            }
       }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-26
      • 1970-01-01
      • 2017-10-02
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      相关资源
      最近更新 更多