Javascript Phonegap插件无法调用android的本机功能
我是phonegap和android的新手 我在phonegap和android中创建了一个插件,使用javascrip调用本机函数 我的简历如下 plugin/BannerLink.js 我的html视图文件 我的BannerLink.java文件 我的config.xml文件Javascript Phonegap插件无法调用android的本机功能,javascript,android,cordova,plugins,native-methods,Javascript,Android,Cordova,Plugins,Native Methods,我是phonegap和android的新手 我在phonegap和android中创建了一个插件,使用javascrip调用本机函数 我的简历如下 plugin/BannerLink.js 我的html视图文件 我的BannerLink.java文件 我的config.xml文件 我正在使用PhoneGap2.0 请纠正我犯的错误。有几个错误是你犯的。“cordova”是小写而不是大写,您只需要在exec方法中提供插件名称而不是完整路径: var BannerLink = { cal
我正在使用PhoneGap2.0
请纠正我犯的错误。有几个错误是你犯的。“cordova”是小写而不是大写,您只需要在exec方法中提供插件名称而不是完整路径:
var BannerLink = {
callNativeFunction: function (success, fail, resultType) {
return cordova.exec(success, fail,
"BannerLink",
"nativeFunction",
[resultType]);
}
};
您试图在Java代码中显示的AlertDialog需要包装为可运行的,例如:
Runnable runnable = new Runnable() {
public void run() {
AlertDialog alertDialog=new AlertDialog.Builder(null).create();
alertDialog.setTitle("Reset...");
alertDialog.show();
};
};
this.cordova.getActivity().runOnUiThread(runnable);
package org.apache.cordova.example;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import android.app.AlertDialog;
import android.util.Log;
@SuppressWarnings("deprecation")
public class BannerLink extends Plugin {
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
// TODO Auto-generated method stub
AlertDialog alertDialog=new AlertDialog.Builder(null).create();
alertDialog.setTitle("Reset...");
alertDialog.show();
Log.d("HelloPlugin", "Hello, this is a native function called from PhoneGap/Cordova!");
//only perform the action if it is the one that should be invoked
return new PluginResult(PluginResult.Status.ERROR);
}
}
<plugin name="BannerLink" value="org.apache.cordova.example.BannerLink"/>
var BannerLink = {
callNativeFunction: function (success, fail, resultType) {
return cordova.exec(success, fail,
"BannerLink",
"nativeFunction",
[resultType]);
}
};
Runnable runnable = new Runnable() {
public void run() {
AlertDialog alertDialog=new AlertDialog.Builder(null).create();
alertDialog.setTitle("Reset...");
alertDialog.show();
};
};
this.cordova.getActivity().runOnUiThread(runnable);