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

androidandroid-intentcordovaplugins

I just downloaded the WebIntent plugin for phonegap, but immediately ran into an error when setting it up. The first few lines of WebIntent.java 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.net.Uri;
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

org.apache.cordova.api.Plugin

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:

    @Override
    public void onNewIntent(Intent intent) {
        if (this.onNewIntentCallback != null) {
            PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
            result.setKeepCallback(true);
            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.

Change

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: http://devgirl.org/2013/09/05/phonegap-3-0-stuff-you-should-know/

Related Question