Marius Bughiu
Marius Bughiu

Reputation: 1017

How to override the camera button in a Windows Phone app?

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.

Upvotes: 2

Views: 2290

Answers (3)

Dan Colasanti
Dan Colasanti

Reputation: 192

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

Upvotes: 1

Volker Voecking
Volker Voecking

Reputation: 5573

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

Upvotes: 2

Christian Amado
Christian Amado

Reputation: 943

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

Regards

Upvotes: -1

Related Questions