android - 尝试调用虚拟方法 '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 不了解
解决方案
尝试使用此代码可能会有所帮助
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()
推荐阅读
- python - 烧瓶循环需要很长时间才能完成
- forms - 颤振小部件内的表单 - 传递表单键
- git - git submodule:如何区分特定的超级项目提交?
- websocket - MQTT Websocket Arduino Uno 与 SIM7600
- javascript - Chartjs 时间戳到日期时间标签
- python - 使用python实现二叉树
- python - Python 使用 BeautifulSoup 和 PIL 从 url 获取图像路径和大小
- android - Android Studio 项目不会为 Main Activity 生成绑定对象
- cmake - CMake:目标不在导出集中
- mysql - InnoDB 缓冲池大小占总 RAM 的百分比 - (总 RAM 的缓冲池大小)返回无数据