How can I check programmatically to see if the user has interacted with an Android Phone's touch screen or keypad? Interaction may be a touch or key press event. Will creating a service for this will help me or not ? How can I do this?
-
2Downvote ? Where is reason ? Please add in comment. – Manish Dubey Dec 21 '12 at 10:04
-
did you checked this http://stackoverflow.com/questions/4208730/how-to-detect-user-inactivity-in-android – surhidamatya Nov 12 '13 at 08:37
2 Answers
If you are talking about doing this in Activity
.. then you can override onUserInteraction() method of the Activity
. Following is the java doc of the method:
Called whenever a key, touch, or trackball event is dispatched to the activity. Implement this method if you wish to know that the user has interacted with the device in some way while your activity is running. This callback and onUserLeaveHint() are intended to help activities manage status bar notifications intelligently; specifically, for helping activities determine the proper time to cancel a notfication.
All calls to your activity's onUserLeaveHint() callback will be accompanied by calls to onUserInteraction(). This ensures that your activity will be told of relevant user activity such as pulling down the notification pane and touching an item there.
Note that this callback will be invoked for the touch down action that begins a touch gesture, but may not be invoked for the touch-moved and touch-up actions that follow.

- 7,425
- 2
- 36
- 44
-
-
User can touch on home screen or open lock of device or press any keypad button or using any app, at that time I want to know that user interacted with their phone. – Manish Dubey Dec 21 '12 at 10:31
-
ok.. Assuming you are developing a real app... why do you want to know that?... what is the use case in your application?... – Praful Bhatnagar Dec 21 '12 at 10:38
-
I can't share use cases of application because of security purpose. – Manish Dubey Dec 21 '12 at 10:41
-
may be you can read system logs and look for launch Activity kind of logs in it... keeping in mind that Starting with Android 4.1 (Jelly Bean), Android apps can read only their own log entries... – Praful Bhatnagar Dec 21 '12 at 12:20
there are so much methods for completing this purpose. You can override on touch event, onclick event on the View instance.

- 490
- 3
- 15
-
I don't have any activity or you can say user interface in my app. – Manish Dubey Dec 21 '12 at 10:11
-
If you don't have any user interface in your app, then where user gonna click? and why do you need to know the user interaction? what kind of questions are you asking man? – Rohit Dec 21 '12 at 10:17
-
User can touch on home screen or open lock of device or press any keypad button, at that time I want to know that user interacted with their phone. – Manish Dubey Dec 21 '12 at 10:20
-
if user touches the home screen or open the lock on their mobile phones, then you are giving him some space/view to touch. then you can get the instance of that view like we do in the case of button. Button b1; b1=(Button)findViewById(R.id.button_id); b1.setOnClickListener(this); – Rohit Dec 21 '12 at 10:27
-
I am not giving any type of user interface or any widgets. Just want to know that user interacted or not? – Manish Dubey Dec 21 '12 at 10:31
-
May be you can find your solution here: http://stackoverflow.com/questions/7513574/how-to-get-sequence-of-user-interaction-with-android-device – Rohit Dec 21 '12 at 10:41