How to get your context in your phonegap plugin

Francis Cebu picture Francis Cebu · Aug 31, 2014 · Viewed 16.8k times · Source

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

Answer

malcubierre picture malcubierre · Aug 31, 2014

try to put this into your plugin:

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