How to enable cookies in android webview?

You should consider that CookieManager.getInstance().setAcceptCookie(true); doesn’t work from lollipop(API21) and above. You should check and use appropriate function for that case: if (android.os.Build.VERSION.SDK_INT >= 21) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true); } else { CookieManager.getInstance().setAcceptCookie(true); }

Error inflating class android.webkit.WebView happens sporadically in production

If you see these reports from devices running Android Lollipop, please ignore them. This likely happens whenever something launches an activity that uses WebView while the WebView package is in the middle of being updated by Play Store (which can only happen on Lollipop currently). During updates, packages are treated as not installed by the … Read more

Android Web-View : Inject local Javascript file to Remote Webpage

There is a way to ‘force’ the injection of your local Javascript files from local assets (e.g., assets/js/script.js), and to circumvent the ‘Not allowed to load local resource : file:///android_assets/js/script.js …’ issue. It is similar to what described in another thread (Android webview, loading javascript file in assets folder), with additional BASE64 encoding/decoding for representing … Read more

How to get the body of the WebResourceRequest in android webView

WebResourceRequest is an interface that can’t read the request body, but you can use your own interface something like this repo dose. https://github.com/KonstantinSchubert/request_data_webviewclient webView.setWebViewClient(new WriteHandlingWebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, WriteHandlingWebResourceRequest request) { // works the same as WebViewClient.shouldOverrideUrlLoading, // but you have request.getAjaxData() which gives you the // request body } });

Enhance webView performance (should be the same performance as native Web Browser)

I finally got the reason of android webview bad performance issue. Notice the image below… It used 12 seconds from OnPageStarted to OnPageFinished. Because it should load CSS,javascript and … AJAX… I notice that JQuery and JQueryMobile need load all DOM struct in Html.So if I lazy load the javascript after OnPageFinished,it should show page … Read more

Load local html in WebView?

You can only do something like that. This solution load HTML from a String variable: String html = “<html><body>Hello, World!</body></html>”; String mime = “text/html”; String encoding = “utf-8”; WebView myWebView = (WebView)this.findViewById(R.id.myWebView); myWebView.getSettings().setJavaScriptEnabled(true); myWebView.loadDataWithBaseURL(null, html, mime, encoding, null); EDIT: try to set the first parameter (the baseURL) of loadDataWithBaseURL() for your needs

Android WebView UTF-8 not showing

Use: mWebView.loadDataWithBaseURL(null, “將賦予他們的傳教工作標示為”, “text/html”, “utf-8”, null); or using WebSettings with setDefaultTextEncoding: WebSettings settings = mWebView.getSettings(); settings.setDefaultTextEncodingName(“utf-8″); For recent versions of Android, API 16 to 22 it was tested and work properly using loadData() method, requires the mimeType to include: “charset=utf-8”. WebView mWebView = (WebView) findViewById(R.id.myWebView); WebSettings settings = mWebView.getSettings(); settings.setDefaultTextEncodingName(“utf-8”); mWebView.loadData(myCharacters, “text/html; charset=utf-8”,null); or mWebView.loadData(myCharacters, … Read more