Trigger for user inactivity?

Post your questions and help other users.

Moderator: Martin

Post Reply
Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Trigger for user inactivity?

Post by Wibbly » 27 Aug 2015 07:54

Is there a trigger for user inactivity (similar to Android's built in Sleep timeout)?

Use case is for where I have a long (or no) Sleep timeout - so the display is on and the device awake - but I want to perform an action after a time of no user interaction.

I kind of want the 'inverse' of the User Present trigger, "User NOT present".

Is there a way to detect, say, when the user last touched the screen (regardless of the app or homescreen the user happens to be on)? Can I use the 'UI Event' trigger in this way?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Trigger for user inactivity?

Post by Martin » 27 Aug 2015 19:16

To my knowledge there's no good way to get access to this information.
You could try Execute Root Command: dumpsys power and see if it includes mLastUserActivityTime and extract the value from there.

Using UI Event could be a workaround but it will also include changes not directly made by the user, for example when Automagic launches an app etc.

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Trigger for user inactivity?

Post by Wibbly » 27 Aug 2015 20:28

Hmm, there might be another approach. Is there a way to determine when a device has gone to sleep because the power button has been pressed rather than becuase the sleep timer has expired? I could detect when the screen goes off (due to the user idle sleep timer), but would need to buld in an exception for when the user themselves has caused this to happen by pressing the power button. I.e. can I just detect when the physical power button is pressed?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Trigger for user inactivity?

Post by Martin » 28 Aug 2015 05:11

That's not easily possible to my knowledge. You could use trigger Command Output to detect the power button press but this method also requires root. The solution with dumpsys power might be even easier.

Wibbly
Posts: 418
Joined: 17 Mar 2014 09:02

Re: Trigger for user inactivity?

Post by Wibbly » 28 Aug 2015 05:44

OK, thanks for your insight

Post Reply