UWP关注

时间:2016-05-25 18:17:33

标签: c# uwp windows-phone led flashlight

我正在使用UWP c#中的Flash和相机API。一切正常(请参阅下面的代码片段)。但是当我关闭手机屏幕时,我想知道如何保持手电筒开启。

因为当我按下手机右侧的电源按钮时,当我再次解锁设备时,闪光灯会自动关闭并且无法开启。我希望手电筒在屏幕关闭时也能激活。

var cameraID = await GetCameraDeviceInfoAsync(Windows.Devices.Enumeration.Panel.Back);
if (cameraID != null)
{
   this.captureManager = new MediaCapture();

   var settings = new MediaCaptureInitializationSettings();
   settings.StreamingCaptureMode = StreamingCaptureMode.Video;
   settings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;
   settings.AudioDeviceId = string.Empty;
   settings.VideoDeviceId = cameraID.Id;

   await this.captureManager.InitializeAsync(settings);

   this.mediaPreview = new CaptureElement();
   this.mediaPreview.Source = this.captureManager;
   await this.captureManager.StartPreviewAsync();
}

var flash = this.captureManager.VideoDeviceController.FlashControl;
flash.Enabled = true;

1 个答案:

答案 0 :(得分:1)

我不知道有没有办法让Windows手机保持手电筒从C#开启。 但是,当通过以下代码查看电话屏幕时,您可以保持应用程序的活动状态。所以你的手电筒也会活着。

表示UWP

Windows.System.Display.DisplayRequest KeepScreenOnRequest = new Windows.System.Display.DisplayRequest();
KeepScreenOnRequest.RequestActive();
WP的

PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;