Android Activity Recognition not working with Nexus 5

后端 未结 3 1113
孤独总比滥情好
孤独总比滥情好 2021-01-23 11:57

I had a code working that was using Google\'s Activity Recognition Updates. Now all of a sudden these seem to send updates either several times per second or never although requ

相关标签:
3条回答
  • 2021-01-23 12:15

    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.

    0 讨论(0)
  • 2021-01-23 12:20

    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.

    0 讨论(0)
  • 2021-01-23 12:24

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

    0 讨论(0)
提交回复
热议问题