简体   繁体   English

谷歌活动识别API不起作用

[英]google activity recognition api not working

I am using Google play services for activity recognition to detect various activities like: Still, On Foot etc. But the code works fine on Moto g devices and fails on HTC one. 我正在使用Google Play服务进行活动识别,以检测各种活动,例如:Still,On Foot等。但是该代码在Moto g设备上运行良好,在HTC设备上运行失败。 Can you please verify if my approach is correct? 您能验证我的方法是否正确吗? Here are the codes: 以下是代码:

My Activity: 我的活动:

public class MyActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    private PendingIntent pIntent;
    GoogleApiClient mGoogleApiClient;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(ActivityRecognition.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
        mGoogleApiClient.connect();
        IntentFilter filter = new IntentFilter();
        filter.addAction("ACTIVITY_RECOGNITION");//For filtering
    }


    @Override

    public void onConnected(Bundle arg0) {
        Intent intent = new Intent(this, ActivityRecognitionService.class);
        pIntent = PendingIntent.getService(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
        ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mGoogleApiClient, 0, pIntent);//0
    }
    /*@Override
    public void onDisconnected() {
    }*/
    //@Override
    public void onConnectionSuspended(int arg0) {
        // TODO Auto-generated method stub      
    } 
    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // TODO Auto-generated method stub  
    }

where as ActivityRecognitionService looks like: 其中ActivityRecognitionService如下所示:

public class ActivityRecognitionService extends IntentService {
public ActivityRecognitionService() {
        super("My Activity Recognition Service");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if(ActivityRecognitionResult.hasResult(intent)){
            ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
            Log.i(TAG, getType(result.getMostProbableActivity().getType()) + "t" + result.getMostProbableActivity().getConfidence());
            /*Intent i = new Intent("ACTIVITY_RECOGNITION");
            i.putExtra("Activity", getType(result.getMostProbableActivity().getType()) );
            i.putExtra("Confidence", result.getMostProbableActivity().getConfidence());
            sendBroadcast(i);*/
            String aType = getType(result.getMostProbableActivity().getType());
            int aConf = result.getMostProbableActivity().getConfidence();
            fileWrite(aType, aConf);
        }
    }

    private String getType(int type){
        if(type == DetectedActivity.UNKNOWN)
            return "Unknown";
        else if(type == DetectedActivity.IN_VEHICLE)
            return "In Vehicle";
}

On HTC i am getting following message in logcat : (Although i got similar messages on moto g, but it still detects the activity) 在HTC上,我在logcat中收到以下消息 :(尽管我在moto g上收到了类似的消息,但它仍检测到活动)

09-28 19:09:11.143: W/asset(7697): Copying FileAsset 0x727dbe28 (zip:/data/app/com.example.activityRec-2.apk:/resources.arsc) to buffer size 254736 to make it aligned.
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/FragmentActivity;)
09-28 19:09:11.173: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.173: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/zzlp;)
09-28 19:09:11.173: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.173: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/zzlp;)
09-28 19:09:11.173: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.173: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Lcom/google/android/gms/internal/zzlp;)
09-28 19:09:11.173: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.173: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to resolve virtual method 21831: Lcom/google/android/gms/internal/zzlp;.zza (ILcom/google/android/gms/common/api/GoogleApiClient;Lcom/google/android/gms/common/api/GoogleApiClient$OnConnectionFailedListener;)V
09-28 19:09:11.173: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.173: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to resolve static method 21829: Lcom/google/android/gms/internal/zzlp;.zza (Landroid/support/v4/app/FragmentActivity;)Lcom/google/android/gms/internal/zzlp;
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/FragmentActivity;)
09-28 19:09:11.173: E/dalvikvm(7697): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.api.GoogleApiClient$Builder.enableAutoManage
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to resolve check-cast 185 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/api/GoogleApiClient$Builder;
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/FragmentActivity;)
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/FragmentActivity;)
09-28 19:09:11.173: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to resolve virtual method 134: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
09-28 19:09:11.183: E/dalvikvm(7697): Could not find class 'android.support.v4.app.NotificationCompat$Builder', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to resolve new-instance 188 (Landroid/support/v4/app/NotificationCompat$Builder;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
09-28 19:09:11.183: E/dalvikvm(7697): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to resolve instanceof 185 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
09-28 19:09:11.183: E/dalvikvm(7697): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to resolve check-cast 185 (Landroid/support/v4/app/FragmentActivity;) in Lcom/google/android/gms/common/GooglePlayServicesUtil;
09-28 19:09:11.183: W/dalvikvm(7697): VFY: unable to resolve virtual method 293: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
09-28 19:09:11.193: W/dalvikvm(7697): VFY: unable to find class referenced in signature (Landroid/support/v4/app/FragmentActivity;)
09-28 19:09:11.193: W/dalvikvm(7697): Unable to resolve superclass of Lcom/google/android/gms/internal/zzlp; (184)
09-28 19:09:11.193: W/dalvikvm(7697): Link of class 'Lcom/google/android/gms/internal/zzlp;' failed
09-28 19:09:11.193: W/dalvikvm(7697): VFY: unable to resolve static method 21829: Lcom/google/android/gms/internal/zzlp;.zza (Landroid/support/v4/app/FragmentActivity;)Lcom/google/android/gms/internal/zzlp;
09-28 19:09:11.193: W/GooglePlayServicesUtil(7697): Google Play services out of date.  Requires 8115000 but found 4324038
09-28 19:09:11.233: I/Adreno-EGL(7697): <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066_msm8974_refs/tags/AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066__release_AU ()
09-28 19:09:11.233: I/Adreno-EGL(7697): OpenGL ES Shader Compiler Version: E031.24.00.06
09-28 19:09:11.233: I/Adreno-EGL(7697): Build Date: 02/06/14 Thu
09-28 19:09:11.233: I/Adreno-EGL(7697): Local Branch: 
09-28 19:09:11.233: I/Adreno-EGL(7697): Remote Branch: refs/tags/AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066
09-28 19:09:11.233: I/Adreno-EGL(7697): Local Patches: NONE
09-28 19:09:11.233: I/Adreno-EGL(7697): Reconstruct Branch: NOTHING
09-28 19:09:49.563: W/GooglePlayServicesUtil(7697): Google Play services out of date.  Requires 8115000 but found 4324038
09-28 19:11:22.253: W/GooglePlayServicesUtil(7697): Google Play services out of date.  Requires 8115000 but found 4324038
09-28 19:11:23.373: W/GooglePlayServicesUtil(7697): Google Play services out of date.  Requires 8115000 but found 4324038

Update 更新资料 订购和出口


update2 error log update2 错误日志

09-29 11:52:13.790: W/asset(10716): Copying FileAsset 0x77fe6e98 (zip:/data/app/com.example.activityRec-1.apk:/resources.arsc) to buffer size 254736 to make it aligned.
09-29 11:52:13.820: W/dalvikvm(10716): VFY: unable to resolve virtual method 236: Landroid/app/Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
09-29 11:52:13.830: W/dalvikvm(10716): VFY: unable to resolve virtual method 527: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
09-29 11:52:13.830: D/At least(10716): it creats
09-29 11:52:13.840: W/GooglePlayServicesUtil(10716): Google Play services out of date.  Requires 8115000 but found 4324038
09-29 11:52:13.880: I/Adreno-EGL(10716): <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066_msm8974_refs/tags/AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066__release_AU ()
09-29 11:52:13.880: I/Adreno-EGL(10716): OpenGL ES Shader Compiler Version: E031.24.00.06
09-29 11:52:13.880: I/Adreno-EGL(10716): Build Date: 02/06/14 Thu
09-29 11:52:13.880: I/Adreno-EGL(10716): Local Branch: 
09-29 11:52:13.880: I/Adreno-EGL(10716): Remote Branch: refs/tags/AU_LINUX_ANDROID_KK_3.5_RB1.04.04.02.006.066
09-29 11:52:13.880: I/Adreno-EGL(10716): Local Patches: NONE
09-29 11:52:13.880: I/Adreno-EGL(10716): Reconstruct Branch: NOTHING

SDK image SDK图片 sdk mgr

The error is because you have missed this part of the support library setup guide 该错误是因为您错过了支持库设置指南的这一部分

In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. 在“顺序和导出”选项卡中,检查刚刚添加到构建路径的.jar文件,以便依赖于该库项目的项目可以使用它们。 For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files. 例如,appcompat项目要求您同时导出android-support-v4.jar和android-support-v7-appcompat.jar文件。

The app runs fine on lollipop because it has the classes needed for card views but the older devices don't hence the need for the support lib. 该应用程序在lollipop上运行良好,因为它具有卡视图所需的类,但是较旧的设备因此不需要支持库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM