简体   繁体   English

如何覆盖 Windows Phone 应用程序中的相机按钮?

[英]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.市场上有一个名为 Flashlight-X 的应用程序,它覆盖此按钮以允许用户打开/关闭手机的 LED 闪光灯。 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.如覆盖默认行为。

On MSDN there is an article describing this:在 MSDN 上有一篇文章描述了这一点:
How to access the hardware camera shutter button in Windows Phone 如何访问 Windows Phone 中的硬件相机快门按钮

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.在 WP7 中,您可以通过使用 Assembly.Load 访问 Microsoft 不受支持的(仅供内部使用)“Microsoft.Phone.Media.Extended”DLL,然后使用反射访问相机并处理快门按下事件来执行此操作。 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 (eg being able to use the camera button under lockscreen).不幸的是,这个 DLL 在 WP8 中不存在,已经被其他媒体 API 取代,这些 API 去除了该程序集的一些复杂性(不需要反射),但也去除了它的一些关键特性(例如能够使用相机锁屏下的按钮)。

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.在 WP8 中,您可以使用 AudioVideoCaptureDevice.OpenAsync 来访问相机设备,但相机按钮事件已移至名为 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在此处了解有关它们的更多信息: http : //msdn.microsoft.com/en-us/library/windowsphone/develop/hh202963(v=vs.105).aspx

You cannot(you shouldn't) override the default behaviour of special buttons (camera, back, start, volume up, volume down, search).您不能(不应该)覆盖特殊按钮(相机、返回、开始、音量增大、音量减小、搜索)的默认行为。

Regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM