I am currently implementing Android Camera 2 as a Preview in a surface viewer on the Android side which then i use custom renderer to show it on my app. Is there a way for me to capture an image when user press on either of the volume button?
Hi @ncmj1998 you can monitor the status of the volume button to capture an image.
public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
//if want VOLUME_DOWN to capture an image , add method here.
//if want VOLUME_UP to capture an image , add method here.
return base.OnKeyDown(keyCode, e);
The codes work however if i put it at MainActivity , the detection is for the whole app. However, i only want the detection to be available when I'm at the page where I have a custom renderer to show a camera preview. I tried putting the code on the activity where I initiliase the renderer but the keycode doesnt seem to get detected .
Ok @ncmj1998 ,if not work in other activity, try to add OnKeyDown method to your custom view not in activity.And view need to set property:SetFocusable(ViewFocusability.Focusable), and you can post code of the activity.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies