本文介绍了行为识别使用新GoogleApiClient不触发活动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用新的GoogleApiClient设立ActivityRecognition在我的应用程序。我找不到任何文件的任何地方(Android官方文档仍引用pcated ActivityRecognitionClient现在去$ P $)。

I am trying to set up ActivityRecognition in my app using the new GoogleApiClient. I couldn't find any documentation anywhere (Official android docs still refer to the now deprecated ActivityRecognitionClient).

在code,我设法写的是不是触发活动更新。

The code that I managed to write is not triggering Activity Updates.

1)里面我MainActivity的onCreate:

1) Inside my MainActivity's onCreate :

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

mGoogleApiClient.connect();

2)内部onConnected:

2) Inside onConnected :

    Intent i = new Intent(this, ActivityRecognitionIntentService.class);
    PendingIntent mActivityRecognitionPendingIntent = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    Log.e("Aditya", "Connected to ActRec");
    ActivityRecognitionApi actRecAPI = new ActivityRecognitionApi()
    {
        public PendingResult<Status> requestActivityUpdates(GoogleApiClient googleApiClient, long l, PendingIntent pendingIntent)
        {
            Log.e("Aditya", "inside requestActivityUpdates()");
            return null;
        }

        public PendingResult<Status> removeActivityUpdates(GoogleApiClient googleApiClient, PendingIntent pendingIntent)
        {
            return null;
        }
    };

    actRecAPI.requestActivityUpdates(mGoogleApiClient, 0, mActivityRecognitionPendingIntent);

我从来没有ActivityRecognitionIntentService收到更新。

My ActivityRecognitionIntentService never receives an update.

我是什么做错了吗?或者是有通过GoogleApiClient任何形式的ActivityRecognition文件的地方?

What am I doing wrong? Or is there any sort of documentation on ActivityRecognition through GoogleApiClient anywhere?

推荐答案

解决它。连接到GoogleApiClient后,我不得不这样做是为了开始接收活动更新。

Solved it. After connecting to GoogleApiClient I just had to do this to start receiving Activity Updates.

ActivityRecognition.ActivityRecognitionApi.
  requestActivityUpdates(mGoogleApiClient, 0, mActivityRecognitionPendingIntent);

无需创建自己的ActivityRecognitionApi对象。

No need to create your own ActivityRecognitionApi object.

这篇关于行为识别使用新GoogleApiClient不触发活动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 13:59