How can I display a pdf document into a Webview?

You can use Google PDF Viewer to read your pdf online: WebView webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); String pdf = “http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf”; webview.loadUrl(“https://drive.google.com/viewerng/viewer?embedded=true&url=” + pdf);

Android Webview – Completely Clear the Cache

I found an even elegant and simple solution to clearing cache WebView obj; obj.clearCache(true); http://developer.android.com/reference/android/webkit/WebView.html#clearCache%28boolean%29 I have been trying to figure out the way to clear the cache, but all we could do from the above mentioned methods was remove the local files, but it never clean the RAM. The API clearCache, frees up the … Read more

how to get html content from a webview?

Actually this question has many answers. Here are 2 of them : This first is almost the same as yours, I guess we got it from the same tutorial. public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); final WebView webview = (WebView) findViewById(R.id.browser); webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new MyJavaScriptInterface(this), “HtmlViewer”); webview.setWebViewClient(new WebViewClient() … Read more

android.view.InflateException Error inflating class android.webkit.WebView

If you use androidx.appcompat:appcompat:1.1.0, try androidx.appcompat:appcompat:1.0.2 instead. it seems that 1.1.0 doesn’t fix the bug with WebView in Android 5.1.1. Feb-2020 update: Reverting to 1.0.2 stopped working for many people (including my app), but using the current version of androidx.appcompat:appcompat:1.2.0-alpha02 did fix the crash. (I was seeing it on a Huawei P8 Lite running Android … Read more

Android WebView: handling orientation changes

If you do not want the WebView to reload on orientation changes simply override onConfigurationChanged in your Activity class: @Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); } And set the android:configChanges attribute in the manifest: <activity android:name=”…” android:label=”@string/appName” android:configChanges=”orientation|screenSize” for more info see: http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange https://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges

Is `shouldOverrideUrlLoading` really deprecated? What can I use instead?

Documenting in detail for future readers: The short answer is you need to override both the methods. The shouldOverrideUrlLoading(WebView view, String url) method is deprecated in API 24 and the shouldOverrideUrlLoading(WebView view, WebResourceRequest request) method is added in API 24. If you are targeting older versions of android, you need the former method, and if … Read more

How to pass html string to webview on android?

i have successfully done by below line //data == html data which you want to load String data = “Your data which you want to load”; WebView webview = (WebView)this.findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadData(data, “text/html; charset=utf-8”, “UTF-8”); Or You can try webview.loadDataWithBaseURL(null, data, “text/html”, “utf-8”, null);