How to get your context in your phonegap plugin

2019-02-05 11:32发布

This is my plugin for android and one of my method requires a context, Is there a way how can I get this context?

public class GaziruPlugin extends CordovaPlugin{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException 
{
    String value = args.getString(0);
    BASE64Decoder decoder = new BASE64Decoder();
    try {
        byte[] imageByte = decoder.decodeBuffer(value);
        Classlogic method = new Classlogic();
        //this method requires a context type.
        method.DoLogic(context,imageByte);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

}

I hope you can help me. Thanks

1条回答
叼着烟拽天下
2楼-- · 2019-02-05 12:16

try to put this into your plugin:

Context context=this.cordova.getActivity().getApplicationContext(); 
查看更多
登录 后发表回答