What is the difference between android view loadData and loadDataWithBaseURL

There are 2 ways to download data in the Android Android browser.

public void loadData (String data, String mimeType, String encoding) 

Please note that a similar source JavaScript policy means that the script runs in the page loaded using this method, will not be able to access the content loaded using any scheme other than "data", including "http (s)". To avoid this limitation, use loadDataWithBaseURL () with the appropriate base URL.

and

 public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 

Please note that contents 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 '.

I do not know what these 2 sentences mean and when to choose between them?

Thank you in advance

+4
source share
3 answers
 public void loadData (String data, String mimeType, String encoding) 

In this we pass HTML, mimeType and encoding

where else in

 public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl) 

where baseUrl can be a base url, such as the path to the resource folder, or sdcard or any other path where your images or other media are associated with your html, and I don't know historyUrl very well

according to the documents [loadData][1]

Note that a similar JavaScript source policy means that a script running on a page loaded with this method will not be able to access content loaded using any other scheme than β€œdata”, including β€œhttp (s)”. To avoid this limitation, use loadDataWithBaseURL() with the appropriate base URL.

means loaddata will only include the part that is in the first parameter.

and

Please note that contents 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", or "javascript".

simple meaning above, you can access data from http and ... others by passing baseUrl

for example . I wrote HTML that required a ton of image from my ftp or other place, what I would do is pass the URL of my ftp in the baseURl parameter, and I can access my images p>

+8
source

The second comes in handy when you download HTML locally and reference resources such as images and css, which are also packaged locally.

+2
source

loadDataWithBaseURL () also comes with Unicode support. This can be useful if you are trying to load a web page with content other than English.

+1
source

Source: https://habr.com/ru/post/984476/


All Articles