2

There is an app in the marketplace called Flashlight-X which overrides this button to allow the user to turn on / off the LED flash of the phone. No matter what you do, pressing the camera button inside that app doesn't bring up the Camera app. How do you achieve this?

I mean, I know how to subscribe to the camera button events, but how do I prevent the default action from happening? As in override the default behavior.

Marius Bughiu
  • 997
  • 14
  • 32
  • did you ever find an answer to this? I'm curious about this too. – Adam Plocher Jan 04 '14 at 02:21
  • Yes. Tho I don't remember exactly what was the trick. I had a look at the code but all I seem to do is subscribe to the camera button events and the button seems to be canceled. Unsubscribe - and the camera pops up. Strange. Maybe it has to do with WP7 / WP8. Try doing that for a WP8 project and see if it works. If not let me know and I will post the source code to my app. – Marius Bughiu Jan 04 '14 at 19:52

3 Answers3

2

On MSDN there is an article describing this:
How to access the hardware camera shutter button in Windows Phone

Volker Voecking
  • 5,203
  • 2
  • 38
  • 35
  • 1
    Subscribing to the events in that article will not prevent the Camera app to pop up. I want to prevent that - like Flashlight-X does. So I'm probably missing something. – Marius Bughiu Feb 10 '13 at 19:44
1

In WP7, you can do this by using Assembly.Load to access Microsoft's unsupported (internal-use-only) "Microsoft.Phone.Media.Extended" DLL and then use reflection to access the camera and handle the shutter pressed events. Unfortunately, this DLL doesn't exist in WP8 and has been replaced by other media APIs, which strip away some of the complexity of that assembly (no reflection needed), but also some of its key features (e.g. being able to use the camera button under lockscreen).

In WP8, you can use AudioVideoCaptureDevice.OpenAsync to get access to the camera device, but the camera button events have been moved to a static class called CameraButtons. You can use those events to override the behavior of the camera buttons in an app. Learn more about them here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202963(v=vs.105).aspx

-1

You cannot(you shouldn't) override the default behaviour of special buttons (camera, back, start, volume up, volume down, search).

Regards

Christian Amado
  • 946
  • 1
  • 7
  • 31
  • You can, and it's been done already. I gave as an example an app that is already on the market and does this. The question is how. – Marius Bughiu Feb 10 '13 at 13:12