Mark Whitaker
Mark Whitaker

Reputation: 8605

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.)

Upvotes: 14

Views: 1913

Answers (2)

M-Wajeeh
M-Wajeeh

Reputation: 17304

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)

Upvotes: 6

XorOrNor
XorOrNor

Reputation: 8978

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

Upvotes: 1

Related Questions