मैं कोशिश करता हूं कि आप पहले क्या करना चाहते हैं, संस्करण 2.0.0 पर फोनगैप पर अपडेट के साथ और प्लगइन के साथ सबसे अच्छा तरीका है। यह संपत्ति फ़ोल्डर के भीतर फोनगैप पर जेएस है। आईडी "nativecall" और एक नमूना बटन के साथ div तत्व का निर्माण करने का पता लगाने के it.Be त्रुटि संदेश की जाँच करने के LogCat देखने के लिए सुनिश्चित करें कि है सुनिश्चित करें।
window.echo = function(str, callback) {
cordova.exec(callback, function(err) {
callback('Nothing to echo.');
}, "Echo", "echo", [str]);
};
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function() {
var abiter = $('#nativecall').html();
$("#abutton").click(function() {
window.echo(abiter, function(echoValue) {
alert(echoValue = abiter); // should alert true.
});
});
}
};
app.initialize();
सेवा पर "ईको" सेवा नाम के साथ नई कक्षा विधि जोड़ें।
package org.apache.cordova.plugin;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.plugin.AndroidActivities;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
/**
* This class echoes a string called from JavaScript.
*/
public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("echo")) {
String message = args.getString(0);
new AndroidPublicFunction(message); //call function from AndroidActivities
this.echo(message, callbackContext);
return true;
}
return false;
}
private void echo(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message);
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
}
पोस्ट त्रुटि लॉग कृपया। –