Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android webview的loadData和loadDataWithBaseURL之间有什么区别_Android_Methods_Webview_Load - Fatal编程技术网

Android webview的loadData和loadDataWithBaseURL之间有什么区别

Android webview的loadData和loadDataWithBaseURL之间有什么区别,android,methods,webview,load,Android,Methods,Webview,Load,Android webview有两种加载数据的方法 public void loadData (String data, String mimeType, String encoding) 请注意,JavaScript的同源策略意味着该脚本在 使用此方法加载的页面将无法访问内容 使用“数据”以外的任何方案加载,包括“https”。到 为避免此限制,请将loadDataWithBaseURL与适当的 基本URL 及 请注意,以这种方式指定的内容可以访问本地设备文件 仅当baseUrl指定的方案不

Android webview有两种加载数据的方法

public void loadData (String data, String mimeType, String encoding)
请注意,JavaScript的同源策略意味着该脚本在 使用此方法加载的页面将无法访问内容 使用“数据”以外的任何方案加载,包括“https”。到 为避免此限制,请将loadDataWithBaseURL与适当的 基本URL

请注意,以这种方式指定的内容可以访问本地设备文件 仅当baseUrl指定的方案不是 “http”、“https”、“ftp”、“ftps”、“关于”或“javascript”

我不知道这两句话是什么意思,什么时候在这两句话中选择


提前感谢

当您在本地加载HTML时,第二个工具会派上用场,它引用了本地打包的图像和css等资产

public void loadData (String data, String mimeType, String encoding)
在这里,我们传递HTML、mimeType和编码

还有别的地方吗

public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
其中baseUrl可以是基本url,例如指向资产文件夹的路径、SD卡或任何其他路径,您的图像或其他媒体所在的位置与html相关,我对historyUrl知之甚少

根据[loadData][1]的文件

请注意,JavaScript的同源策略意味着使用此方法加载的页面中运行的脚本将无法访问使用“数据”以外的任何方案加载的内容,包括“https”。要避免此限制,请将loadDataWithBaseURL与适当的基本URL一起使用

意味着loaddata将只包括驻留在第一个参数中的部件

请注意,仅当baseUrl指定的方案不是“http”、“https”、“ftp”、“ftps”、“about”或“javascript”时,以这种方式指定的内容才能通过“file”方案URL访问本地设备文件

上面的简单意思是您可以从http和。。。其他方法是通过传递baseUrl


例如,我编写的HTML需要从我的ftp或其他地方获取大量图像,我要做的是在baseURl参数中传递我的ftp的url,我可以访问我的图像

loadDataWithBaseURL还提供Unicode支持。当你试图用英文以外的内容加载网页时,这可能会有帮助。其中提到:-用于从自己的计算机中检索文件。在我们的例子中,它是电话,scheme在这个上下文中意味着什么?请浏览链接,它会很有帮助。这是否意味着使用null作为基本url将允许我从不同的域访问javascript?我一直在想,setWebViewClient如何比较??
public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)