Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a custom Plugin for Cordova2.3 - Android
    primarykey
    data
    text
    <p>I am trying to create a custom plugin for Cordova - android. The purpose of the plugin is to raise an intent for a native android activity on click of a button on an HTML5 screen. So initially, I would be on an HTML5 screen with a button. On click of button, I should be redirected to a native android activity screen. </p> <p>Here is a bit of code I have already done,</p> <p>customplugin.js</p> <pre><code>function CustomPlugin(){}; CustomPlugin.prototype.launchActivity = function(startClass) { alert("@@@ Starting plugin to launch native activity."); cordova.exec(null, null, 'CustomPlugin', 'launchActivity', [startClass]); }; if(!window.plugins) { window.plugins = {}; } if (!window.plugins.customplugin) { window.plugins.customplugin = new CustomPlugin(); } </code></pre> <p>In this code, however, I am getting 'Uncaught TypeError: cannot call method "launchActivity" of undefined.' Pls help me with some sample code examples. Thanks in advance.</p> <p>CustomPlugin.java</p> <pre><code>package org.apache.cordova.example; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; import android.util.Log; public class CustomPlugin extends CordovaPlugin { @Override public boolean execute(String action, final JSONArray args, CallbackContext callbackContext) throws JSONException { if ("launchActivity".equals(action)) { String goClass = null; if(args.length() &gt; 0) goClass = args.getString(0); Log.i("NATIVE", "Launch class : " + goClass); return true; } else { return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload