How to get your context in your phonegap plugin

只谈情不闲聊 提交于 2019-11-29 04:38:44

问题


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:


try to put this into your plugin:

Context context=this.cordova.getActivity().getApplicationContext(); 


来源:https://stackoverflow.com/questions/25592206/how-to-get-your-context-in-your-phonegap-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!