简体   繁体   中英

How can i create Flashlight app in uwp C#

I have Lumia 830 and i've tried to create flashlight app in UWP C#. my device Flashlight works great but i don't know why i can't create my own app turn on / off Torch of my phone. I use Lamp class :

var lamp = await Lamp.GetDefaultAsync();

if (lamp == null)
{
    ShowErrorMessage("No Lamp device found");
    return;
}
lamp.IsEnabled = true;

when run this code on my phone "lamp" is null and it couldn't find my FlashLED. I've got this code from MSDN.Microsoft.com and thay said

If the returned object is null, the Lamp API is unsupported on the device. Some devices may not support the Lamp API even if there is a lamp physically present on the device.

This class doesn't work on my Lumia 830 i don't kno why? :(

also i use this code :

var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync();
var videoDev = mediaDev.VideoDeviceController;

var tc = videoDev.TorchControl;
if (tc.Supported)
{
// But wait, for this to work with Blue camera drivers, we have to Start a recording session
// Create video encoding profile as MP4 
var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);

// Start Video Recording
var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
                await mediaDev.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);

// Turn on Torch                 
mediaDev.VideoDeviceController.TorchControl.Enabled = true;
}

this code works and my FlashLED turn on but it record video and it take's user SD Card memory. please help me if you know there is best way to turn on/off Torch or FlashLED. thanks in advance Hussein Habibi Juybari

The Lamp API is designed for Windows 10 devices only and you can only use it on devices which support the API. Currently supported devices are 950/950XL, 650, and 550. Older devices will not be updated to support this API. You should fall back to the Windows 8.1 method of turning on flash when you detect that the lamp device is not available on older devices.

From: https://wpdev.uservoice.com/forums/110705/suggestions/15846967

Please test default sample named LampDevice (cf. https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/LampDevice ). Do you have the same behavior ? I just tested on Lumia 930 it works fine. No Lumia 830 to test it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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