I'm using Android webView to show a html page, I have a share option on my page. when webpage load onto Android WebView and tapping on the share button nothing happening, How can i show the Share Sheet in android web view
viewBinding.webView.apply {
setBackgroundResource(R.drawable.window_bg);
setBackgroundColor(android.graphics.Color.TRANSPARENT)
settings.apply {
javaScriptEnabled = true
builtInZoomControls = false
displayZoomControls = false
allowFileAccess = true
allowContentAccess = true
domStorageEnabled = true
}
}
viewBinding.webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
viewBinding.webView.visibility = View.GONE
viewBinding.progressBar.visibility = View.GONE
}
override fun onPageFinished(view: WebView?, url: String?) {
viewBinding.progressBar.visibility = View.GONE
viewBinding.webView.visibility = View.VISIBLE
}
override fun onReceivedError(
view: WebView,
request: WebResourceRequest,
error: WebResourceError
) {
super.onReceivedError(view, request, error)
}
override fun shouldOverrideUrlLoading(webView: WebView, url: String): Boolean {
if (url.startsWith("http"))
return false //open web links as usual
if (url.startsWith("intent:")) {
val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME)
val data = intent.data
data?.let {
try {
val scheme = data.scheme
if (FACEBOOK_APP_SCHEMA == scheme) {
startActivity(intent)
return true
}
} catch (e: ActivityNotFoundException) {
val marketIntent = Intent(Intent.ACTION_VIEW).setData(
Uri.parse("$PLAY_STORE_URL${intent.getPackage()}")
)
if (marketIntent.resolveActivity(packageManager) != null) {
this@WebViewActivity.startActivity(marketIntent)
return true
}
}
}
}
return false
}
}
viewBinding.webView.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest?) {
request?.grant(request.resources);
}
override fun onShowFileChooser(
webView: WebView?,
filePathCallback: ValueCallback<Array<Uri>>?,
fileChooserParams: FileChooserParams?
): Boolean {
uploadMessage?.onReceiveValue(null)
uploadMessage = null
uploadMessage = filePathCallback
val intent = fileChooserParams!!.createIntent()
try {
startActivityForResult(intent, REQUEST_SELECT_FILE)
} catch (e: ActivityNotFoundException) {
uploadMessage = null
Toast.makeText(
applicationContext,
"Cannot Open File Chooser",
Toast.LENGTH_LONG
).show()
return false
}
return true
}
}
viewBinding.webView.loadUrl(URL)
}