试图将Google Pay集成到我的Android应用中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了试图将Google Pay集成到我的Android应用中相关的知识,希望对你有一定的参考价值。
我正在尝试将Google Pay集成到我的android应用中。我正在追踪发现的this tutorial,但是当我运行代码时,却不断收到此错误E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.sqill, PID: 12555
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=upi://pay?pa=your-merchant-vpa@xxx&pn=your-merchant-name&mc=your-merchant-code&tr=your-transaction-ref-id&tn=your-transaction-note&am=your-order-amount&cu=INR pkg=com.google.android.apps.nbu.paisa.user }
到目前为止是我的代码。在此先感谢
// PaymentPageActivity.java
Button pay_button;
final int UPI_PAYMENT=0;
Integer amount=5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_page);
pay_button=findViewById(R.id.pay);
//startActivity
pay_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
payUsingUpi();
}
});
}
private void payUsingUpi() {
Uri uri =
new Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "your-merchant-vpa@xxx")
.appendQueryParameter("pn", "your-merchant-name")
.appendQueryParameter("mc", "your-merchant-code")
.appendQueryParameter("tr", "your-transaction-ref-id")
.appendQueryParameter("tn", "your-transaction-note")
.appendQueryParameter("am","$5.00")
.appendQueryParameter("cu", "INR").build();
String GOOGLE_PAY_PACKAGE_NAME = "com.android";
int GOOGLE_PAY_REQUEST_CODE = 123;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_PAY_PACKAGE_NAME);
startActivityForResult(intent, GOOGLE_PAY_REQUEST_CODE);
}
您可能使用了错误的软件包名称。根据以下example:
String GOOGLE_PAY_PACKAGE_NAME = "com.google.android.apps.nbu.paisa.user";
int GOOGLE_PAY_REQUEST_CODE = 123;
Uri uri =
new Uri.Builder()
.scheme("upi")
.authority("pay")
.appendQueryParameter("pa", "your-merchant-vpa@xxx")
.appendQueryParameter("pn", "your-merchant-name")
.appendQueryParameter("mc", "your-merchant-code")
.appendQueryParameter("tr", "your-transaction-ref-id")
.appendQueryParameter("tn", "your-transaction-note")
.appendQueryParameter("am", "your-order-amount")
.appendQueryParameter("cu", "INR")
.appendQueryParameter("url", "your-transaction-url")
.build();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(GOOGLE_PAY_PACKAGE_NAME);
activity.startActivityForResult(intent, GOOGLE_PAY_REQUEST_CODE);
包裹名称应为com.google.android.apps.nbu.paisa.user
。
以上是关于试图将Google Pay集成到我的Android应用中的主要内容,如果未能解决你的问题,请参考以下文章
Google Pay UPI 集成在 Android 中不起作用