【问题标题】:Trying to integrate google pay to my android app试图将谷歌支付集成到我的安卓应用中
【发布时间】:2023-04-04 08:32:01
【问题描述】:

我正在尝试将 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);
    }

【问题讨论】:

    标签: android google-pay


    【解决方案1】:

    您可能使用了错误的包名。根据以下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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2013-07-07
      相关资源
      最近更新 更多