- // Create a WebView asset loader. TODO.
- // val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
+ // Create a WebView asset loader.
+ val webViewAssetLoader = WebViewAssetLoader.Builder().addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(requireContext())).build()
+
+ // Set a WebView client.
+ webView.webViewClient = object : WebViewClient() {
+ // Send external links to a web browser.
+ override fun shouldOverrideUrlLoading(view: WebView, webResourceRequest: WebResourceRequest): Boolean {
+ // Create an intent to view the URL.
+ val urlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ urlIntent.data = webResourceRequest.url
+
+ // Make it so.
+ startActivity(urlIntent)
+
+ // Consume the click.
+ return true
+ }
+
+ // Process asset requests with the asset loader.
+ override fun shouldInterceptRequest(webView: WebView, webResourceRequest: WebResourceRequest): WebResourceResponse? {
+ // This allows using the `appassets.androidplatform.net` URL, which handles the loading of SVG files, which otherwise is prevented by the CORS policy.
+ return webViewAssetLoader.shouldInterceptRequest(webResourceRequest.url)
+ }
+ }