Ron
Ron

Reputation: 513

Error developing phonegap cordova 2.2.0 plugin for android

I'm trying to write a PhoneGap Cordova 2.2.0 plugin for Android, but I'm having issues, and I'm unsure what the cause is.

Here is my JS:

PushCapure.js

var PushCapture = { 
        init : function () { 
            console.log('Attempting to call the PushCapture plugin');
            return cordova.exec(function() {
                alert('PushCapture was successful');
            }, function(error) {
                alert('PushCapture failed');
            }, "PushCapture", "capture", []);
        } 
};

Now here is my native code I want to run

com.ron.camanon.PushCapture.java

package com.ron.camanon;

import org.apache.cordova.api.CordovaPlugin;
import android.util.Log;

public class PushCapture extends CordovaPlugin {  

    public void capture()
    {
        Log.i("PushCapture", "PushCapture called, capture video stream intended...");
    }
} 

This isn't working for me, I've also added this line to my res/config.xml :

<plugin name="PushCapture" value="com.ron.camanon.PushCapture"/>

The error callback is the only thing that is executed when I try my plugin.

What am I doing wrong?

This is Cordova 2.2.0 for Android

Upvotes: 0

Views: 941

Answers (1)

MikeIsrael
MikeIsrael

Reputation: 2889

That isn't how the plugins work in Android, looks like you are using the iOS model where it calls a certain method. In Android the "method" or specific command for the plugin will be sent as a string within the exec function see the code example below from the Phonegap tutoral for plugins on Android

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("beep".equals(action)) {
        this.beep(args.getLong(0));
        callbackContext.success();
        return true;
    }
    return false;  // Returning false results in a "MethodNotFound" error.
}

Upvotes: 2

Related Questions