【问题标题】:How to get your context in your phonegap plugin如何在 phonegap 插件中获取上下文
【发布时间】:2014-08-31 12:56:46
【问题描述】:

这是我的 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;
}

}

我希望你能帮助我。谢谢

【问题讨论】:

    标签: android cordova cordova-plugins


    【解决方案1】:

    尝试将其放入您的插件中:

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

    【讨论】:

    • 谢谢!我一直在寻找 this.cordova.getContext() 但结果是 this.cordova.getActivity().getApplicationContext();所以谢谢你的回答。
    • 任何人都知道电容的情况吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多