How can I detect if physical camera button is being held-down?

  • Replies:2
  • OpenNot stickiedUnanswered

Jul 12, 2013 12:13:51 AM

(I am using an HTC Evo 4G LTE as my device, with Jellybean)

I am using a service with a broadcast receiver, after I close my main activity.

I can detect the standard long-press of the camera button, but I need a method of detecting if its being held down for say, 6 seconds or something.

Jul 17, 2013 11:26:39 AM

A Service can't access the UI thread so it's not possible for a Service to detect key presses.

If you want to detect the key press within the Activity, probably the best solution is launch and 6 second post delayed handler that will check if the user still has the key pressed down.

Something like:
new Handler().postDelayed(/* your Runnable here */, 6000);

Jul 17, 2013 9:07:07 PM

Henrique Rocha
A Service can't access the UI thread so it's not possible for a Service to detect key presses.

If you want to detect the key press within the Activity, probably the best solution is launch and 6 second post delayed handler that will check if the user still has the key pressed down.

Something like:
new Handler().postDelayed(/* your Runnable here */, 6000);

Thats odd you say so, because I am detecting key presses via my service.

I am intrigued about your suggestion with the delayed handler though, sounds good.

Perhaps a flag checking for camera key down or key up, then handler checks 6 seconds later for that flag.