问题
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