Enthusiastic_girl
Enthusiastic_girl

Reputation: 21

How to enable UPI payment part in webview in android app

I have an e-commerce website where at the end I need to make payment, where it shows 4 UPI payment app options (BHIM,phonePe,gPay,paytm).but when I try to click those UPI app option buttons, it shows error as Webpage not available..webpage at intent://pay?pa=..net: ERR_UNKNOWN_URL_SCHEME .... I have tried url.startswith("upi") but it is not working.... How can I fix this ?

Upvotes: 2

Views: 1697

Answers (1)

Swapnil33
Swapnil33

Reputation: 97

I was finding its solution too. I got the answer after asking chatGPT.

in your webViewClient class add following override method.

override fun shouldOverrideUrlLoading(
        view: WebView?,
        request: WebResourceRequest?
    ): Boolean {
        val uri = request!!.url
        if (uri.scheme == "upi") {
            // Handle UPI URL
            val intent = Intent(Intent.ACTION_VIEW, uri)
            startActivity(intent)
            return true // Indicate WebView to not load the URL
        }
        return super.shouldOverrideUrlLoading(view, request)
    }

Upvotes: 0

Related Questions