Android - GoogleApiClient ActivityRecognitionIntentService is never called

佐手、 提交于 2019-12-24 22:13:07

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/29604897/android-googleapiclient-activityrecognitionintentservice-is-never-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!