5

I'm using Transitions API and everything works fine for the first 24-48 hours - I receive physical activity changes from the API, but after 24-48 hours there's nothing.

Under Transitions API Receiver, I use Foreground Service that is still alive after those 48 hours. I can verify that by seeing logs; additionally, Location (Fused Location Client) updates are still coming in after those 24-48 hours whereas Transition API seems to be dead.

Has anyone experienced this? I do think that maybe resetting (unregister and then register again) Transitions API using Worker might be alternative (every 1-2 hrs). Not sure if this would help. I have a feeling this happens when app enters Doze mode/some kind of sleep state.

Also, my foreground service uses exported=false, maybe setting it to true would help? (I would love for someone to give an answer and explaining why you should use one or another)

OS: Android 12

MaaAn13
  • 264
  • 5
  • 24
  • 54

1 Answers1

5

On devices that have significant motion sensor, the battery is conserved by stopping activity reporting when the device is still for an extended period of time. It'll resume once devices move again.

This is mention in Google Developer Video

UPDATE:

Motion is considered a device movement, such as tilt, shake, rotation, or swing. And it must ne significant (not small) motion. you can test it in this way.

private SensorManager sensorManager;
private Sensor sensor;
private TriggerEventListener triggerEventListener;
...
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);

triggerEventListener = new TriggerEventListener() {
    @Override
    public void onTrigger(TriggerEvent event) {
        // Do work
    }
};

sensorManager.requestTriggerSensor(triggerEventListener, mSensor);
user16930239
  • 6,319
  • 2
  • 9
  • 33
  • 1
    even with plugged in device? – Link182 Nov 26 '22 at 22:39
  • 1
    @Link182 yes, even plugged in devices, this depends on movement. – user16930239 Nov 27 '22 at 04:34
  • 1
    @Jabbar Mentioned video talks about "Activity Recognition" and not "Activity Transitions" - but I'd assume the same logic applies for the latter? Also, in my case, the phone is in my car, meaning, while I do not touch my phone for several days (unlock and use different apps), motion sensor should notice when the car starts moving, right? It does not... (or should the user interact with the mobile - unlock it to expect activity transitions api to pick up new states?) – MaaAn13 Nov 28 '22 at 07:00
  • 1
    @MaaAn13 its actually called [Activity Recognition Transition API](https://developer.android.com/codelabs/activity-recognition-transition#0). Also your car movement could be considered insignificant because the phone is sitting, I've update my answer with a way to test significant movement. – user16930239 Nov 28 '22 at 07:42
  • @Jabbar I implemented your solution of SIGNIFICATION MOTION logging, from my logs I can see that onTrigger gets triggered now and then indicating that we have done motion, but after second day we do not get updates in onReceive Transitions API method (while we keep receiving significant motion now and then; location updates are received as well). Any ideas? – MaaAn13 Dec 12 '22 at 07:16
  • @MaaAn13 what is the model of the phone or tablet you are using? Also, did you try this on other devices? – user16930239 Dec 12 '22 at 07:41
  • @Jabbar I tried two devices. One is Google 3A, Android 12. For this model it's super bad, because at some point I do not even get logs of significant motion (sensor returns null after 48hrs), while the other older device at least logs out significant motion, but do not have onReceive activity updates (first 48hrs is okay). Quite weird.. – MaaAn13 Dec 12 '22 at 11:25