3

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?

Manish Dubey
  • 4,206
  • 8
  • 36
  • 65

2 Answers2

0

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.

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44
-1

there are so much methods for completing this purpose. You can override on touch event, onclick event on the View instance.

Rohit
  • 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