To invoke Samsung Pay application in WebView, you should override the shouldOverrideUrlLoading method.
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 const val SAMSUNG_APP_STORE_URL: String = "samsungapps://ProductDetail/com.samsung.android.spay"
}
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 or Samsung App Store deep link
if (url.startsWith(SAMSUNG_PAY_URL_PREFIX) || url.startsWith(SAMSUNG_APP_STORE_URL), ignoreCase = false) {
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
}
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
developer.samsung.com, .samsung.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
Samsung Electronics
.samsung.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
Samsung Electronics
developer.samsung.com, google.account.samsung.com
Preferences Submitted
You have successfully updated your cookie preferences.