What is the difference between Android webview's loadData and loadDataWithBaseURL
public void loadData (String data, String mimeType, String encoding)
In this we pass the HTML, mimeType and encoding
where else in
public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
where baseUrl could be the base url such as the path to asset folder, or SDCard or any other path, where your images or the other media resides related to your html, and I am not much aware of historyUrl
accoring to the docs of [loadData][1]
Note that JavaScript's same origin policy means that script running in a page loaded using this method will be unable to access content loaded using any scheme other than 'data', including 'http(s)'. To avoid this restriction, use
loadDataWithBaseURL()
with an appropriate base URL.
means loaddata
will only include the part which is resides in the first parameter.
and
Note that content specified in this way can access local device files (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
simple meaning of above is you can access the data from http and... other by passing the baseUrl
for example I have written HTML which required tons of image from my ftp or other place what I would do is pass the url of my ftp in baseURl parameter and I can access to my images
WebView.loadData not working on Android 9.0 (API-29)
I solved my problem, the problem occurs in Smartphones that has latest Chrome.
SOLUTION:
Do not use
mWebview.loadData
method, instead use
mWebview.loadDataWithBaseURL
As a result my solution is:
mWebview.loadDataWithBaseURL(null,htmlContent,"text/html", "utf-8", null);
Android webviews and loadData()
It is common problem with loadData(String data, String mimeType, String encoding)
method,
replace it with
loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
Related Topics
Notifydatasetchange Not Working from Custom Adapter
How to Get Root Permissions Through the Android Sdk
No Internet on Android Emulator - Why and How to Fix
Can't Get Write_Settings Permission
How to Remove a Button or Make It Invisible in Android
How to Apply a Style to All Buttons of an Android Application
Is Uploading Videos from an Sd Card to Facebook Possible with the Facebook Sdk
Move Layouts Up When Soft Keyboard Is Shown
How to Prevent Android Bluetooth Rfcomm Connection from Dying Immediately After .Connect()
How to Change Package Name of Android Project in Eclipse
Changing the Android Overflow Menu Icon Programmatically
How to Maintain Multi Layers of Imageviews and Keep Their Aspect Ratio Based on the Largest One
Software Keyboard Resizes Background Image on Android
Convert Content:// Uri to Actual Path in Android 4.4
Android Drawable Images from Url
How to Interface with the Badgeprovider on Samsung Phones to Add a Count to the App Icon