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

  • Replies:2
Andrew Cox
  • Forum posts: 4

Jul 12, 2013, 12:13:51 AM via Website

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

Reply
Deactivated Account
  • Forum posts: 131

Jul 17, 2013, 11:26:39 AM via Website

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

Reply
Andrew Cox
  • Forum posts: 4

Jul 17, 2013, 9:07:07 PM via Website

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.

Reply