UPI Intent in WebView – Android
Enable UPI Intent payments inside a WebView in your Android application.
This allows UPI apps like Google Pay, PhonePe, Paytm, and other UPI-compliant apps to open seamlessly from a WebView flow.
Steps to Enable UPI Intent
- Add a WebView to your Android app
- Handle deep links inside
shouldOverrideUrlLoading()usingWebViewClient
Add WebView to Android App
Add a WebView to your layout XML file:
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Handle Deep Links in shouldOverrideUrlLoading()
Intercept UPI deep links and launch the corresponding UPI application using an Intent.
In this example, we check for common UPI schemes such as:
upitezphonepepaytmmp
If a UPI scheme is detected, the app launches the external UPI application.
Otherwise, normal HTTP/HTTPS URLs continue loading inside the WebView.
Android Example (Java)
package com.example.appname;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(
WebView view,
WebResourceRequest request
) {
return handleUrl(view, request.getUrl());
}
private boolean handleUrl(WebView view, Uri url) {
String scheme = url.getScheme();
if (scheme == null) return false;
// Match common UPI apps by scheme
if (scheme.matches("upi|tez|phonepe|paytmmp")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(url);
startActivity(intent);
return true;
} catch (Exception e) {
// No matching UPI app installed
System.out.println(
"No UPI app found. Please install a UPI app."
);
return false;
}
}
// Load non-UPI URLs inside WebView
view.loadUrl(url.toString());
return true;
}
});
webView.loadUrl("https://www.example.com");
}
}
Supported UPI Intent Apps
The following UPI apps are commonly supported for Mobile Web flows:
- Google Pay
- PhonePe
- Paytm
- Other UPI-compliant apps
The Other option triggers any compatible UPI payment app installed on the user's device.
Best Practices
- Always validate the URL scheme before launching intents
- Provide user feedback if no UPI app is installed
- Test on real devices (emulators may not have UPI apps)