首页 > 解决方案 > 尝试调用虚拟方法 'android.content.Context.intent.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)'

问题描述

public void callInstamojoPay(String email, String phone, String amount, String purpose, String buyername) {
    final Activity activity = this;
    InstamojoPay instamojoPay = new InstamojoPay();
    IntentFilter filter = new IntentFilter("ai.devsupport.instamojo");
    registerReceiver(instamojoPay, filter);
    JSONObject pay = new JSONObject();
    try {
        pay.put("email", email);
        pay.put("phone", phone);
        pay.put("purpose", purpose);
        pay.put("amount", amount);
        pay.put("name", buyername);
        pay.put("send_sms", true);
        pay.put("send_email", true);
    } catch (JSONException e) {
        e.printStackTrace();
    }        
    initListener();

    instamojoPay.start(activity, pay, listener);

}

InstapayListener listener;


public void initListener() {
    listener = new InstapayListener() {
        @Override
        public void onSuccess(String response) {
            Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG)
                    .show();
        }

        @Override
        public void onFailure(int code, String reason) {
            Toast.makeText(getApplicationContext(), "Failed: " + reason, Toast.LENGTH_LONG)
                    .show();
        }
    };
}

-----------------------------------------


尝试调用虚拟方法
出现错误
请帮我解决问题。
我是原生反应新手,我对 android 不了解

标签: androidreact-native

解决方案


尝试使用此代码可能会有所帮助

private void callInstamojoPay(String email, String phone, String amount, String purpose, String buyername) {
    final Activity activity = this;
    InstamojoPay instamojoPay = new InstamojoPay();


    IntentFilter filter = new IntentFilter("ai.devsupport.instamojo");
    Instamojo.initialize(YourActivity.this);



    registerReceiver(instamojoPay, filter);
    JSONObject pay = new JSONObject();
    try {
        pay.put("email", email);
        pay.put("phone", phone);
        pay.put("purpose", purpose);
        pay.put("amount", amount);
        pay.put("name", buyername);
        pay.put("webhook",BuildConfig.WEBHOOK_URL);
        pay.put("send_sms", true);
        pay.put("send_email", true);
        pay.put("description",purpose);

        Log.e(TAG, "callInstamojoPay: "+pay );
    } catch (JSONException e) {
        e.printStackTrace();
    }
    initListener();

    instamojoPay.start(activity, pay, listener);
}

在 onCreate() 中调用 init initListener()


推荐阅读