Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:25:57+00:00 2026-06-16T03:25:57+00:00

I am using Cordova 2.1.0 to develop an Android plugin. The plugin code is

  • 0

I am using Cordova 2.1.0 to develop an Android plugin.

The plugin code is as follows

package org.apache.cordova.example;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MyTestPlugin extends Plugin {
  /**
  * Executes the request and returns PluginResult.
  *
  * @param action        The action to execute.
  * @param args          JSONArry of arguments for the plugin.
  * @param callbackId    The callback id used when calling back into JavaScript.
  * @return              A PluginResult object with a status and message.
  */
  public PluginResult execute(String action, JSONArray args, String callbackId) {
    try {
      if (action.equals("echo")) {
        String echo = args.getString(0);
        if (echo != null && echo.length() > 0) {
          return new PluginResult(PluginResult.Status.OK, echo);
        } else {
          return new PluginResult(PluginResult.Status.ERROR);
        }
      } else {
        return new PluginResult(PluginResult.Status.INVALID_ACTION);
      }
    } catch (JSONException e) {
      return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
  }
}

HTML/JS Code

<script type="text/javascript" src="cordova-2.1.0.js"></script>
<script type="text/javascript">
  window.echo = function(str, callback) {
    alert('Started');
    cordova.exec(callback, callback, "MyTestPlugin", "echo", [str]);
    alert('The END');
  };
  window.onload = function () {
    alert('1st Step');
    window.echo("echo", function(echoValue) {
      alert(echoValue == "echo"); // should alert true.
    });
    alert('SecondStep');
  };
</script>
</html>

Config.xml

But I am not able to invoke the plugin. Can somebody please help me in getting this issue rectified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:25:59+00:00Added an answer on June 16, 2026 at 3:25 am

    Plugins cannot be called until the deviceredy event has fired.

    window.onload could and probably will happen before deviceready.

    http://docs.phonegap.com/en/2.2.0/cordova_events_events.md.html#deviceready

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've to develop a simple Android app using the Cordova API(PhoneGap) and it requires
I'm using Cordova 1.9.0 for an Android App. The same code, on IOS works
I'm building an hybrid Android App using Phonegap/Apache Cordova. My app should get data
I am trying to write a file in android using phonegap cordova 1.5.0. Below
I am using JQM 1.1.0 and Cordova 1.5.0. I have code like this <!DOCTYPE
I am using cordova(phonegap) 2.1.0 for IOS app development. When i execute my code
I am currently working with an hybrid HTML5 mobile application using Cordova. My code
Am developing a android application using phonegap(Cordova 2.0.0). I need the retrieve the device
I am using cordova for mobile app development on android platform. I have this
I'm trying to detect shaking event using Cordova 2.2.0 for android devices. I found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.