Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a notification whenever the user interacts with an Android device?

Is it possible in Android API level 15 to receive a notification whenever the user does anything that keeps the device awake - in effect, whenever PowerManager.userActivity() is called?

(Bit of background: I'm working on a large Android app for a non-mobile device with a fixed power supply. When the user interacts with the screen, keyboard, etc. I need to send a "stay awake" signal to another, connected device.)

like image 600
Mark Whitaker Avatar asked Oct 17 '13 13:10

Mark Whitaker


Video Answer


2 Answers

Well if its your own Activity then you can always use onUserInteraction() and onUserLeaveHint() methods.

An alternative way is to listen for all touch events from a Service using techniques mentioned here: Creating a system overlay window (always on top)

like image 136
M-WaJeEh Avatar answered Nov 14 '22 15:11

M-WaJeEh


Wouldn't it be enought to trigger your signal on android.intent.action.ACTION_SCREEN_ON (when the screen is ON) or android.intent.action.USER_PRESENT broadcast? Read more here: http://developer.android.com/reference/android/content/Intent.html#ACTION_USER_PRESENT

like image 21
XorOrNor Avatar answered Nov 14 '22 14:11

XorOrNor