android - 尝试将 google pay 集成到我的 Android 应用程序中

标签 android google-pay

我正在尝试将 google pay 集成到我的 Android 应用程序中。我正在关注this tutorial我发现了,但是当我运行我的代码时,我不断收到此错误 E/AndroidRuntime: FATAL EXCEPTION: main 进程:com.myapp.sqill,PID:12555 android.content.ActivityNotFoundException:找不到处理 Intent 的 Activity { 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

关于android - 尝试将 google pay 集成到我的 Android 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61417463/

相关文章:

android - 有人可以解释 SQLiteOpenHelper getType

android - 有没有办法可以通知应用程序来自设备的指纹已被注销?

android - 如何使用 Google Pay 设置送货回调

web - Google Pay API 与 Payment Request API 有什么区别?

firebase - Chrome 中的哪个标志?到 Firebase 的 Chrome?

android - AIDE "Unknown entity ' R'"Android Studio 应用程序项目出错

android - fragment 和旋转

android - 多 Activity 应用程序退出

google-pay - Google Pay 如何判断用户的付款方式?

android - Google Pay(Tez) 集成到我的支付网关中吗? (安卓)