Activity Recognition API does not work continuously

后端 未结 2 1504
遥遥无期
遥遥无期 2021-01-24 13:38

I\'m testing Activity Recognition API in 2 apps : Google sample code and implementation of this code in my app.

The problem is both apps keeps getting activity recognit

相关标签:
2条回答
  • 2021-01-24 14:22

    Your IntentService might "stop", I would say "fall asleep" because of:

    To conserve battery, activity reporting may stop when the device is 'STILL' for an extended period of time. It will resume once the device moves again. This only happens on devices that support the Sensor.TYPE_SIGNIFICANT_MOTION hardware.

    Basically it should be the case for most of the devices with API >= 20.

    Please find more here.

    Unfortunately, you can only request activity updates and it is impossible to force ActivityRecognitionApi to continuously give current activity even if it is "still" for some mysterious "extended period of time".

    In my opinion, it would much more convenient if this feature of ActivityRecognitionApi was configurable.

    0 讨论(0)
  • 2021-01-24 14:30

    Even registering broadcast receiver in Manifest file,you need to register in dynamically in Oreo+ otherwise it will not work. Try this.Add this code in main activity or in startCommand in Service.It worked for me.I have tested this code on Android 10 too..worked perfectly.You need not to register broadcast receiver in Manifest file.

    @Override
        protected void onStart() {
            super.onStart();
            IntentFilter intentFilter=new IntentFilter(Constants.BROADCAST_DETECTED_ACTIVITY);
        intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
            registerReceiver(broadcastReceiver,intentFilter);
    
        }
    
    0 讨论(0)
提交回复
热议问题