Configure WebView enablements

  1. To invoke Samsung Pay application in WebView, you should override the shouldOverrideUrlLoading method.
  2. Javascript and DOM Storage are disabled in a WebView by default. You can enable the both through the WebSettings attached to your WebView.
    WebSettings allows any website to use JavaScript and DOM Storage. For more information, visit WebSettings.
  • Sample code (Kotlin)
import android.webkit.webView
import android.webkit.webViewClient
import android.content.Intent
import android.content.ActivityNotFoundException

companion object {
    private const val SAMSUNG_PAY_URL_PREFIX: String = "samsungpay"
}

private lateinit var webView: WebView

webView.settings.run {
    javaScriptEnabled = true
    domStorageEnabled = true
}

webView.webViewClient = object: WebViewClient() {
    override fun shouldOverrideUrlLoading(
        view: WebView,
        request: WebResourceRequest
    ): Boolean {
        // get URL from WebResourceRequest
        val url = request.url.toString()

        // add below if statement to check if URL is Samsung Pay deep link
        if (url.startsWith(SAMSUNG_PAY_URL_PREFIX)) {
            try {
                val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
                startActivity(intent)
            } catch (e: ActivityNotFoundException) {
                // Exception would be occured if the Samsung Wallet app is not installed.

                // go to install Samsung Wallet app from market
                val installIntent = Intent.parseUri("samsungapps://ProductDetail/com.samsung.android.spay", Intent.URI_INTENT_SCHEME)
                installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                startActivity(installIntent)
            }
            // return true will cause that the URL will not be loaded in WebView
            return true
        }
        // the remaining part of the shouldOverrideUrlLoading method code

        // return false when you want to load URL automatically by WebView
        return false
    }
}