Cordova Windows Phone 8 Plugin Development Overview

Source: Internet
Author: User
Tags requires

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.