【问题标题】:UWP keep light onUWP 保持点亮
【发布时间】:2016-05-25 18:17:33
【问题描述】:

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

因为当我按下手机右侧的电源按钮时,当我再次解锁设备时,闪光灯会自动关闭并且不会打开。即使屏幕关闭,我也希望手电筒处于活动状态。

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;

【问题讨论】:

    标签: c# uwp windows-phone led flashlight


    【解决方案1】:

    我不知道 windows phone 有没有办法让 C# 中的手电筒保持打开状态。 但是当通过以下代码查看手机屏幕时,您可以保持应用程序处于活动状态。所以你的手电筒也会有生命的。

    对于 UWP

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

    对于 WP

    PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
    

    【讨论】:

    • 我想知道,那些火炬应用程序是如何做到的。我在商店里尝试了一个,当关闭屏幕或离开应用程序时,它继续打开。所以我想,一定有什么诡计。
    • 我仍在寻找解决方案。我会尽快发布解决方案,因为我可以找到它。但到目前为止还没有运气
    猜你喜欢
    • 2023-01-13
    • 2020-04-11
    • 1970-01-01
    • 2010-09-11
    • 2019-05-03
    • 1970-01-01
    • 2016-07-23
    • 2019-03-20
    • 1970-01-01
    相关资源
    最近更新 更多