The previous blog describes the installation deployment on the Cordova WP8 platform, Cordova extensions can take advantage of WP8 local code to extend WebApp functionality, invoking local capabilities requires the development of appropriate plug-ins, the following flash as an example to describe the detailed steps to create a WP8 plug-in, Open and close two interface functions for a flash implementation.
1. Create Plug-in class
Create Flash plug-in class flashlight need to inherit basecommand, usually we will create the plugins directory in the Engineering directory to store the plug-in class. The FlashLight.cs file is created in the plugins directory.
Write the FlashLight.cs file and add the following code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using Windows.Phone.Media.Capture;
Using Wpcordovaclasslib.cordova;
Using WPCordovaClassLib.Cordova.Commands;
Namespace Testcordova.plugins {class Flashlight:basecommand {///<summary>///Flash Instance
</summary> protected static Audiovideocapturedevice Device {get; set;} <summary>///turn on flash///</summary>///<returns></returns> Pub
Lic async Task Trunon (string options) {var sensorlocation = Camerasensorlocation.back; try {if (Device = null) {//Get Audioviceocapturedevi Ce Device = await audiovideocapturedevice.openasync (sensorlocation, Audiovideocapturedevice.getavailab Lecaptureresolutions (sensorlocation).
(a)); //Open flash var supportedcameramodes = Audiovideocapturedevice.getsupport
Edpropertyvalues (Sensorlocation, Knowncameraaudiovideoproperties.videotorchmode); if (Supportedcameramodes.tolist (). Contains ((UInt32) videotorchmode.on)) {Device.setproperty (Knowncameraaudiovideopropert ies.
Videotorchmode, Videotorchmode.on); Set Brightness to Maximum Device.setproperty (Knowncameraaudiovideoproperties.videotorchpower, Audiovideocapturedevice . Getsupportedpropertyrange (Sensorlocation, Knowncameraaudiovideoproperties.videotorchpower).
MAX); //Return status Dispatchcommandresult (new Pluginresult (PluginResult.Status.OK, "{data: OK}")
")); The flash cannot be controlled by catch (Exception ex) {//, returning the Error state Dispatchcommandresult (n
EW Pluginresult (PluginResult.Status.JSON_EXCEPTION)); }///<summary>///turn off flash///</summary> public void trunof
F (String options) {var sensorlocation = Camerasensorlocation.back; try {var supportedcameramodes = Audiovideocapturedevice.
Getsupportedpropertyvalues (Sensorlocation, Knowncameraaudiovideoproperties.videotorchmode); Turn off the flash if (Device!= null && supportedcameramodes.tolist (). Contains ((UInt32) videotorchmode.off)) {Device.setproperty (knowncameraaudiovideoproper Ties.
Videotorchmode, Videotorchmode.off); //Return status Dispatchcommandresult (new Pluginresult (PluginResult.Status.OK, "{data: OK}")
")); The flash cannot be controlled by catch (Exception ex) {//, returning an error status System.Diagnostics.Debu
G.writeline (ex);Dispatchcommandresult (New Pluginresult (PluginResult.Status.JSON_EXCEPTION)); }}} Flashlight
Because calling the flash requires some ability to turn on hardware, you need to configure the Wmappmanifest.xml file to check Id_cap_isv_camera and Id_cap_microphone.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/