From 46fec2cbbc87c6cad1d07f654dfe9087c5737027 Mon Sep 17 00:00:00 2001 From: shmoxy Date: Tue, 20 Nov 2018 13:38:48 +0100 Subject: [PATCH] intent fix --- .../activity/main/MainActivity.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt b/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt index 94e6a66..68323d2 100644 --- a/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt +++ b/app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt @@ -732,8 +732,27 @@ class MainActivity : Activity() { tab.webView.webChromeClient = tab.webChromeClient tab.webView.webViewClient = object : WebViewClient() { - override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { - return super.shouldOverrideUrlLoading(view, url) + override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean { + val url: String = request?.url.toString() + + if( URLUtil.isNetworkUrl(url) ) { + return false + } + + val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME) + + intent.putExtra("URL_INTENT_ORIGIN", view?.hashCode()) + intent.addCategory(Intent.CATEGORY_BROWSABLE) + intent.component = null + intent.selector = null + + if (intent.resolveActivity(this@MainActivity.packageManager) != null) { + startActivityIfNeeded(intent, -1) + + return true + } + + return false } override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {