> ## Documentation Index
> Fetch the complete documentation index at: https://razorpay-881012b3.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# UPI Intent in WebView - Android

> Enable UPI Intent in WebView on your Android app.

<div style={{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0.35rem 0.9rem",border:"1px solid rgba(128,128,128,0.28)",borderRadius:"0.5rem",padding:"0.45rem 0.75rem",margin:"0 0 1.25rem",fontSize:"0.875rem"}}>
  <span style={{fontWeight:600}}>Available in</span>
  <span>🇮🇳 India</span>
</div>

Follow the steps given below to enable UPI intent in WebView on your android application:

**1.1** [Add WebView to Android App](#1-1-add-webview-to-android-app)

**1.2** [Setup WebViewClient](#1-2-setup-webviewclient)

**1.3** [Handle Deep Links in shouldOverrideUrlLoading()](#1-3-handle-deep-links-in-shouldoverrideurlloading)

**1.4** [Enable UPI Intent Support](#1-4-enable-upi-intent-support)

## 1.1 Add WebView to Android App

Add a WebView to the layout of your Android app. You can add the code given below to the layout XML file of your app:

```xml theme={null}
<WebView
   android:id="@+id/webview"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />
```

## 1.2 Setup WebViewClient

To setup a `WebViewClient` that handles URL requests, create a new class using the code given below extending the `MyWebViewClient` and overriding the `shouldOverrideUrlLoading()` method.

<CodeGroup>
  ```java Java theme={null}
  class MyWebViewClient extends WebViewClient {

      private Activity activity;

      public MyWebViewClient(Activity activity) {
          this.activity = activity;
      }

      /** This function is used to handle deeplink in webview */
      @Override
      public Boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
          return true;
      }

  }

  // Use CustomWebviewClient created above in the webview object.
  class MainActivity extends Activity {

      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          WebView webView = findViewById(R.id.webview);
          webView.setWebViewClient(new MyWebViewClient(MainActivity.this));
      }

  }
  ```

  ```kotlin Kotlin theme={null}
  class MyWebViewClient(private val activity: Activity) : WebViewClient() {
      override fun onPageFinished(view: WebView?, url: String?) {
          super.onPageFinished(view, url)
      }

      /** This function is used to handle deeplink in webview */
      override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
          return true
      }
  }

  // Use CustomWebviewClient created above in the WebView object.
  class MainActivity : Activity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          val webView = findViewById<WebView>(R.id.webview)
          webView.setWebViewClient(MyWebViewClient(this@MainActivity))
      }
  }
  ```
</CodeGroup>

## 1.3 Handle Deep Links in shouldOverrideUrlLoading()

To handle deep links in the `shouldOverrideUrlLoading()` method, check if the URL is a deep link and then launch the corresponding activity using the intent class. In this example, we are checking if the URL starts with `http://` or `https://`. If not, then we create a new intent with `ACTION_VIEW` and URL as the data and start the activity with this intent.

<CodeGroup>
  ```java Java theme={null}
  import android.app.Activity;
  import android.content.ActivityNotFoundException;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.net.Uri;
  import android.webkit.WebResourceRequest;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;

  class MyWebViewClient extends WebViewClient {

      @Override
      public void onPageFinished(WebView view, String url) {
          super.onPageFinished(view, url);
      }

      /** This function is used to handle deeplink in webview */
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
          String url = request.getUrl().toString();
          if (!url.startsWith("https") || !url.startsWith("http")) {
              try {
                  Intent i = new Intent(Intent.ACTION_VIEW);
                  i.setData(Uri.parse(request.getUrl().toString()));
                  activity.startActivityForResult(i, 2001);
              } catch (ActivityNotFoundException ignored) {

              }
          }
          return true;
      }
  }
  ```

  ```kotlin Kotlin theme={null}
  import android.app.Activity
  import android.content.ActivityNotFoundException
  import android.content.Intent
  import android.graphics.Bitmap
  import android.net.Uri
  import android.webkit.WebResourceRequest
  import android.webkit.WebView
  import android.webkit.WebViewClient

  class MyWebViewClient(private val activity: Activity): WebViewClient() {

     override fun onPageFinished(view: WebView?, url: String?) {
         super.onPageFinished(view, url)

     }

      /** This function is used to handle deeplink in webview */
      override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
         val url = request!!.url.toString()
         if (!url.startsWith("https") || !url.startsWith("http")){
             try {
                 val i = Intent(Intent.ACTION_VIEW)
                 i.setData(Uri.parse(request.url.toString()))
                 activity.startActivityForResult(i, 2001)
             } catch (e: ActivityNotFoundException) {

             }
         }
         return true

     }

  }
  ```
</CodeGroup>

## 1.4 Enable UPI Intent Support

To enable and test UPI intent in WebView-based Checkout:

1. Open your website integrated with custom checkout.
2. Pass `webview_intent: true` parameter in the [payload](/docs/payments/payment-gateway/web-integration/custom/build-integration#1-3-2-instantiate-custom-checkout) sent to checkout to enable UPI intent support.
3. Ensure that UPI intent is triggered when the payment request is made.

<Warning>
  **Watch Out!**

  By default, the top PSP apps appear on the customer's mobile irrespective of the installation status of the UPI apps.
</Warning>

## List of Supported UPI Intent Apps

Given below is the list of supported UPI apps for Mobile Web.

* `gpay`
* `phonepe`
* `paytm`
* `any`

The `any` option triggers the other UPI payment apps installed on your customer's mobile.
