How to show PDF document as a HTML document in a WebView
Create WebView.xml
<WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" />
Create assets folder and paste HTML document into it.
privacy_policy.html
Implementing loading document in activity or fragment.
val webview:WebView = findViewById(R.id.webview) webView.getSettings().setJavaScriptEnabled(true) webView.webViewClient = object : WebViewClient() { override fun onReceivedError( view: WebView?, request: WebResourceRequest?, error: WebResourceError? ) { super.onReceivedError(view, request, error) // Log or handle the error here Log.e("WebView", "Error loading page: $error") } } webView.loadUrl("file:///android_asset/privacy_policy.html");
Tagged: