2014-08-31 36 views
34

这是我的android插件,我的一个方法需要一个上下文,有没有办法让我获得这个上下文?如何在你的手机插件中获取你的上下文

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; 
} 

}

我希望你能帮助我。由于

回答

68

尝试把这个变成你的插件:

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

谢谢!我正在寻找this.cordova.getContext(),但事实证明它是this.cordova.getActivity()。getApplicationContext();所以谢谢你的回答。 – jfmg 2015-06-11 11:22:18

相关问题