Home:ALL Converter>Custom Cordova Plugin

Custom Cordova Plugin

Ask Time:2012-09-22T20:16:16         Author:sebastian

Json Formatter

I'm trying to write a custom plugin for Cordova 2.0.0. The custom plugin that I want to make has to get the WP accent color, so I can use it in the app Style.

But I can't manage to make it work properly and can't figure it out what I'm doing wrong.

Index.js

function onDeviceReady() {
    click();
}
function click() {
    navigator.notification.alert(callback, callback, "text", "button");
    window.getAccentColor();
}

GetTheme.cs

namespace Cordova.Extension.Commands
 {
   // Use the phonegap base class
   public class GetTheme : BaseCommand 
   {
     public void Get()
     {
         Color currentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"];
         var result = new PluginResult(PluginResult.Status.OK, currentColorHex.ToString());
         DispatchCommandResult(result);
     }
   }
 }

GetTheme.js

window.getAccentColor = function () {
    cordova.exec(win, error, "GetTheme", "Get");
}

function win(result) {
    console.log(result);
    console.log("2");
};


function error() {
}

There a some things a bit strange that I've noticed. With the notification pop-up on the click action "2" is written in the output. But without it doesn't output anything.

In both cases result from the win function is still empty and doesn't output anything.

All the *.js files are included in the index.html file in the head section. The callback method from the notification is defined but it does nothing.

I've also tried with the WP7CordovaClassLib.Cordova.Commands namespace.

Author:sebastian,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12543658/custom-cordova-plugin
pradeek :

From the Cordova documentation page, \n\n// all JS callable plugin methods MUST have this signature!\n// public, returning void, 1 argument that is a string\n\n\nSo, in your GetTheme.cs, change\n\n public void Get()\n\n\ninto \n\n public void Get(string options) \n",
2012-09-25T17:32:36
CedricB :

finding the answers to these questions will help you (and us) understand why your plugin is not being called....\n\n\nIs onDeviceReady being called? \nIs click being called?\nThis looks foreign to me \"navigator.notification.alert(callback,\ncallback, \"text\", \"button\");\" what is that supposed to do\nDoes the output window of VS.NET show any JS errors that are\npreventing the rest of your js from executing?\n",
2012-09-28T18:41:20
yy