Android – WebIntent plugin for Phonegap: Cannot find import org.apache.cordova.api.Plugin


I just downloaded the WebIntent plugin for phonegap, but immediately ran into an error when setting it up. The first few lines of are

import java.util.HashMap;
import java.util.Map;

import org.apache.cordova.DroidGap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.util.Log;
import android.text.Html;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;


public class WebIntent extends Plugin {

Eclipse recognizes all of these imports except for


After some research, I discovered that Phonegap 2.0 wants plugins to extend the Plugin class. Phonegap 2.7 wants plugins to extend "CordovaPlugin" instead.

A quick look at the Phonegap github reveals that no class called "Plugin" even exists in that package anymore. This confuses me because the WebIntent github was updated just a few months ago, and it still uses Plugin.

I tried changing Plugin to CordovaPlugin wherever I could find it in the file. Surprisingly, most of the errors vansihed. However, the onNewIntent method still has an error:

    public void onNewIntent(Intent intent) {
        if (this.onNewIntentCallback != null) {
            PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
            this.success(result, this.onNewIntentCallback);

"success(…)" is not a function in CordovaPlugin and there is no function similar to it.

Can anyone think of a way to solve this problem? Or is there information that I'm missing? (A more up-to-date version of WebIntent would be fantastic, but I can't seem to find one)

Best Solution

Had the same problem upgrading to Phonegap 3.0 and found solution is not only change plugin to CordovaPlugin but also you will need to remove "api" from the import statement.


import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

To this:

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;

Answer reference:

Related Question