Android - GoogleApiClient ActivityRecognitionInten

2019-09-09 20:10发布

I need to detect user dynamics in my application. I started by using GooglePlayServicesClient which till three months ago worked perfectly, Then it stopped working on my HTC one device (although it was still working on three different devices I've checked). I know it is now replaced by GoogleApiClient, so I thought this was my problem, but it keeps not working even after changing to the new API. The problem is that the intent given to ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates is never called. I used the same implementation as : https://blacode.wordpress.com/2014/12/26/user-activity-recognition-through-new-activityrecognitionapi-in-android-activityrecognitionclient-deprecated/ (And again, this implementation works on three other devices but not on HTC one).

I did some reading online and I saw some similar issues that were solved by updating google play or activating google play location services or disable mock location on the android developers settings. Non worked for me.

Has anyone encountered the same problem or maybe has some idea what can be the cause?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-09 20:42

Eventually what solved it was resetting the device to manufacturer settings, meaning that the problem was some setting in the device , which I still have no clue to what caused it. If anyone finds an answer I'll be glad to hear about it.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-09-09 20:57

If your onHandleIntent is not being triggered, make sure you have a receiver tag in your manifest (inside the application tag, but outside the activity) :

    <service
        android:name=".ActivityRecognitionIntentService"
        android:exported="false" />

I struggled with this for several hours before finally realizing this was missing. As soon as I added it, everything worked.

Also, if you add an IntentService class through the AndroidStudio submenu for IntentService instead of just adding a plain Java class and setting it up yourself, it will automatically be registered in the manifest. New...->Service->IntentService

查看更多
登录 后发表回答