Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get your context in your phonegap plugin

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

like image 968
Francis Cebu Avatar asked Aug 31 '14 12:08

Francis Cebu


People also ask

What is PhoneGap plugin?

Apache Cordova and Adobe PhoneGap provide a way for developers to develop apps for all major platforms in HTML, CSS and JavaScript. Developers only have to maintain a single codebase for all platforms. The project started out as PhoneGap and when it was acquired by Adobe the code was released as Apache Cordova.


1 Answers

try to put this into your plugin:

Context context=this.cordova.getActivity().getApplicationContext();  
like image 107
malcubierre Avatar answered Sep 24 '22 12:09

malcubierre