Android Activity Recognition not working with Nexus 5

北战南征 提交于 2019-12-02 07:14:48

I would suggest you increase the detection interval, it takes at least 6 to 7 seconds for the sensors to detect a change in your activity. Also, I have observed that ActivityRecognition stops firing intents if the device is Still for a certain period of time. They are immediately triggered when the device is in motion again.

Perhaps you have the location services disabled on your Nexus 5 device...
Activity Recognition needs the location services active/enabled.

Emmanuel Francis Narvasa Ramos

As suggested by canopi, increase the detection 'time', in which 0 will give you the fastest result.

I had encountered the same problem and instead of adding the build() part on onCreate directly, I added the method below and called it on onCreate(). Try to trace the code from this google sample. I got the code stripped down from there.

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(ActivityRecognition.API)
            .build();
}

Also add buildGoogleApiClient() to your onCreate method.

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