从CordovaPlugin打开活动CordovaPlugin

2023-09-03 22:57:06 作者:凉薄人

我已经写了CordavaPlugin派生类。

I have written a CordavaPlugin derived class.

public class ShowMap extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args,
        CallbackContext callbackContext) throws JSONException {

    if (action.compareTo("showMap") == 0)
    {
        String message = args.getString(0); 
        this.echo(message, callbackContext);

        Intent i = new Intent();


        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.");
    }
}

}

我从这个类要打开一个新的活动。 如何获得访问PhoneGap的基础类的原始环境?

I want from this class to open a new activity. How do I get access to the original context of the phonegap based class?

推荐答案

尝试为:

    Context context=this.cordova.getActivity().getApplicationContext();
    //or Context context=cordova.getActivity().getApplicationContext();
    Intent intent=new Intent(context,Next_Activity.class);

    context.startActivity(intent);
    //or cordova.getActivity().startActivity(intent);

和确保你已经在的Andr​​oidManifest.xml

相关推荐