admin管理员组文章数量:1387360
Opening PDFs coming from another web link. PDFs are supposed to be downloaded from the link and then an external app is used to open to PDF. This applies for all the resources.
.xlsx .pdf .jpeg
Opening PDFs coming from another web link. PDFs are supposed to be downloaded from the link and then an external app is used to open to PDF. This applies for all the resources.
.xlsx .pdf .jpeg
1 Answer
Reset to default 0For this, we need to understand what Android does behind the picture. When we open a web view through WebViewClient
it considers everything as an unrelated resource. If we want to open a PDF from the web view itself, we can override onLoadResource
.
class CustomWebViewClient: WebViewClient()
{
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean
{
if (request == null)
{
return false
}
view!!.settings.allowFileAccess = true
view.settings.allowContentAccess = true
view.settings.domStorageEnabled = true
view.settings.javaScriptEnabled = true
view.settings.loadWithOverviewMode = true
view.loadUrl(request.url.toString())
return false
}
override fun onLoadResource(view: WebView?, url: String?) {
super.onLoadResource(view, url)
if (url!!.contains(".pdf")) {
WebHelper.openBrowser(url.toUri())
}
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
super.onReceivedError(view, request, error)
Log.e("error", error.toString())
}
}
本文标签: kotlinHow to load resources coming from the webview in androidStack Overflow
版权声明:本文标题:kotlin - How to load resources coming from the webview in android? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744569207a2613240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论