Context is null while using Telr Payment Gateway in android

Viewed 149

I am integrating Telr payment gateway in my app. I have used code from there dummy project which is working fine, I used their code in my fragment but it is throwing null context error. I have tried everything like "getContext" , "getApplicationContext" etc. but showing me error that context is null

Code :

    public void sendMessage() {
    Intent intent = new Intent(getActivity(), WebviewActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);

    intent.putExtra(WebviewActivity.EXTRA_MESSAGE, getMobileRequest());
    intent.putExtra(WebviewActivity.SUCCESS_ACTIVTY_CLASS_NAME, "com.marketplace.activity.SuccessTransationActivity");
    intent.putExtra(WebviewActivity.FAILED_ACTIVTY_CLASS_NAME, "com.marketplace.activity.FailedTransationActivity");
    intent.putExtra(WebviewActivity.IS_SECURITY_ENABLED, isSecurityEnabled);
    startActivity(intent);
}

enter image description here

1 Answers

There is a variable 'a' that exists in TelrApplication class. extend your application with TelrApplication. This will resolve your problem.

public class TelrApplication extends Application {
    private static Context a;

    public TelrApplication() {
    }

    public void onCreate() {
        super.onCreate();
        Log.d("Hany", "Context Started....");
        a = this.getApplicationContext();
    }

    public static Context a() {
        return a;
    }
}
Related