1.创建cordova项目,添加平台android
cordova create LocalCordova com.hjk.cordova CordovaApp
2.使用plugman创建自定义插件
plugman create --name HjkPlugin --plugin_id HjkPlugin --plugin_version 1.0.0
调用java代码如下:
package org.apache.cordova.hjkplugin;
import android.content.Intent;
import com.hjk.cordova.LocalActivity;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONException;
public class HjkPlugin extends CordovaPlugin{
@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
if("jumpHjk".equals(action)){
Intent intent =new Intent(this.cordova.getActivity(), LocalActivity.class);
this.cordova.getActivity().startActivity(intent);
return true;
}
return false;
}
}<