Implement Android Telephony or phone locale to get the user's country code. The example code is as follows:
Get country code from Telephony:
fun getCountryFromTelephony(): String? {
val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
return tm.simCountryIso ?: tm.networkCountryIso
}
Get country code from phone locale:
fun getCountryFromPhoneLocale(context: Context): String? {
val locale = context.resources.configuration
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale.locales[0].country
} else {
locale.locale.country
}
}
It is recommended to set up the WebView with the following:
webView.settings.javaScriptEnabled = true webViewGamePlay.settings.domStorageEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true
webView.settings.allowContentAccess = true
webView.settings.databaseEnabled = true
webView.settings.loadsImagesAutomatically = true
It is required to set up WebChromeClient with the following:
webView.webChromeClient = object: WebChromeClient() {
override fun onCreateWindow(
view: WebView?,
isDialog: Boolean,
isUserGesture: Boolean,
resultMsg: Message
): Boolean {
val newWebView = WebView(presenter.presentedView.context)
val webSettings = newWebView.settings
webSettings.javaScriptEnabled = true
val dialog = Dialog(context)
dialog.setContentView(newWebView)
dialog.show()
dialog.window?.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)
newWebView.webChromeClient = object : WebChromeClient() {
override fun onCloseWindow(window: WebView) {
dialog.dismiss()
}
}
(resultMsg.obj as WebView.WebViewTransport).webView = newWebView
resultMsg.sendToTarget()
return true
}
}