I am working on a UPI APP. I want to add my app as an option for payment via UPI, in dialog with other payment app

486 Views Asked by At

I have added intent-filter in the activity where I am doing the payments. Here are the details:

<activity>
......
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="upi" />

</intent-filter>
</activity>

and Activity code for receiving intent is:

var intent = getIntent();

I need my app to come as an opton while doing payment via UPI.

1

There are 1 best solutions below

0
Shubham Kumar Mahato On

To allow users to choose your app for UPI payments, you can create a dialog with a list of payment apps and launch it when the user clicks a "Pay with UPI" button

val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("upi://pay?id=1234&amount=100")
val paymentApps = packageManager.queryIntentActivities(intent, 0)
val paymentAppNames = paymentApps.map { it.loadLabel(packageManager) }
val paymentAppIcons = paymentApps.map { it.loadIcon(packageManager) }

val adapter = PaymentAppListAdapter(paymentAppNames, paymentAppIcons)
val dialog = AlertDialog.Builder(this)
    .setTitle(R.string.pay_with_upi)
    .setAdapter(adapter) { _, which ->
        val chosenPaymentApp = paymentApps[which]
        val chosenPaymentAppName = chosenPaymentApp.loadLabel(packageManager)
        val chosenPaymentAppPackage = chosenPaymentApp.activityInfo.packageName
        intent.setPackage(chosenPaymentAppPackage)
        startActivity(intent)
    }
    .create()

buttonPay.setOnClickListener {
    dialog.show()
}

also make sure to create a custom adapter for payment apps