简体   繁体   English

Webview从文件中加载图像但不在Android中从Web加载图像

[英]Webview load images from file but not from web in android

Hello I want to load a HTML data into a WiebView. 您好,我想将HTML数据加载到WiebView中。 My html data contains two images, one is in the asset folder and the other is located on the web. 我的html数据包含两个图像,一个位于资产文件夹中,另一个位于Web上。 My code is something like this: 我的代码是这样的:

String html  = "<html><body><img src="image1.jpg"><img src="http://www.example.com/images/image2.jpg"></body></html>";

webView = (WebView) rootView.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8",null);

But the webview only loads the first image and does not load the web image. 但是Web视图仅加载第一张图像,而不会加载Web图像。 Can anyone help me to solve the problem? 谁能帮助我解决问题?

Your code is ok (except for the unescaped quotes) but you probably forgot to request internet permissinon for the webview. 您的代码还可以(除了未转义的引号外),但您可能忘记了请求Webview的Internet Permitinon。 Add this to your manifest file: 将此添加到清单文件中:

<uses-permission android:name="android.permission.INTERNET" />

first to add internet permission in manifest. 首先在清单中添加互联网许可。 second to write: 第二写:

webView.loadDataWithBaseURL("http:///android_asset/", html, "text/html", "UTF-8",null);

not: 不:

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8",null);

because http shows web and file shows internal memory 因为http显示网络,文件显示内部存储器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM