Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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中使用html代码打开本地存储的图像?_Android_Html_Image_Jsoup - Fatal编程技术网

如何在android中使用html代码打开本地存储的图像?

如何在android中使用html代码打开本地存储的图像?,android,html,image,jsoup,Android,Html,Image,Jsoup,我使用jsoup解析html和webview来显示html内容。在此过程中,我正在更改图像的源。因此,在html中执行这一行时 图像未加载,即图像有剩余空间,但不包含实际图像。我如何在android中实现这一点? 这是我正在使用的代码 private void showJson(String json) { ParseJSON pj = new ParseJSON(json); pj.parseJSON(); String[] instru

我使用jsoup解析html和webview来显示html内容。在此过程中,我正在更改图像的源。因此,在html中执行这一行时

图像未加载,即图像有剩余空间,但不包含实际图像。我如何在android中实现这一点? 这是我正在使用的代码

    private void showJson(String json) {
        ParseJSON pj = new ParseJSON(json);
        pj.parseJSON();
        String[] instruction = ParseJSON.instruction;


        for (int i = 0; i < instruction.length; i++)
        {

            Document doc = Jsoup.parse(instruction[i]);

            if (doc.select("img[src]").attr("src").contains("download-r.png"))
            {
                Elements image = doc.select("img[src]");
                String imgsource = image.attr("src");
                downloadImages(imgsource);
                Boolean isSDPresent = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
                if (isSDPresent)
                {
                    image.attr("src","sdcard/rreadyreckoner_images/download-r.png");
                }else
                {
                    image.attr("src","/storage/emulated/0/rreadyreckoner_images/download-r.png");
                }
            }
            Log.d("Clean", String.valueOf(doc));
//            String imgsrc = images.attr("src");

            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadData(String.valueOf(doc),"text/html","UTF-8");


            Elements paragraphs = doc.select("ul li ");
            for (Element element: paragraphs)
            {
                Log.d("PARAGRAPHS",element.text());

            }



            //Log.d("SOURCE",imgsrc);
            //Toast.makeText(MainActivity.this, imgsrc, Toast.LENGTH_SHORT).show();

        }
    }
private void showJson(字符串json){
ParseJSON pj=新的ParseJSON(json);
pj.parseJSON();
String[]指令=ParseJSON.instruction;
for(int i=0;i
这是我试图在webview中显示的html

<html>
   <head></head>
   <body>
      <ul>
         <li>The Comprehensive R Archive Network</li>
         <li>A network of global web servers storing identical, up-to-date, versions of<br />code and documentation for R</li>
      </ul>
      <p><br /><strong>Download and Install R:</strong></p>
      <ul>
         <li>Use the CRAN mirror nearest to you to download R setup at a faster<br />speed. Go to <a href="url"> http://cran.r-project.org</a></li>
         <li>Select one of the three download links according to your machine.</li>
      </ul>
      <img src="sdcard/rreadyreckoner_images/download-r.png" alt="downloadr" width="191" height="129" /> 
      <ul>
         <li>Run the R set up and follow the instructions of the installer.</li>
      </ul>
   </body>
</html>

  • 综合档案网络
  • 一个全球web服务器网络,存储相同的、最新的
    代码版本和R的文档

下载并安装R:

  • 使用离您最近的CRAN mirror以更快的速度下载R安装程序。去
  • 根据您的机器选择三个下载链接之一
  • 运行R设置并按照安装程序的说明进行操作
我得到以下错误

chromium:[信息:控制台(1)]“不允许加载本地资源: file:///sdcard/rreadyreckoner_images/download-r.png"

您必须使用以获取SD卡的实际路径:

 Boolean isSDPresent = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
                if (isSDPresent)
                {
                    image.attr("src", Environment.getExternalStorageDirectory() + "/rreadyreckoner_images/download-r.png");
                }else
                {
                    image.attr("src","/storage/emulated/0/rreadyreckoner_images/download-r.png");
                }
我建议通过以下方法将图像加载到WebView中:
myWebView=(WebView)findViewById(R.id.WebView);
myWebView.getSettings().setAllowFileAccess(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().SetBuilTinZoomControl(true);
String imagePath=“file://”+Environment.getExternalStorageDirectory().getAbsolutePath()+“rreadyreckoner\u images/download-r.png”;
//创建一个html模板。
字符串html=“”;
//将图像加载到WebView中:
loadDataWithBaseURL(“,html,“text/html”,“utf-8”,”);

如何在android中使用html代码打开本地存储的图像?
因此,当html加载图像时,图像不会加载???这毫无意义。
使用jsoup解析和显示html内容
。不能使用jsoup显示html内容。请重新措辞。非常抱歉@greenapps请检查我更新的问题。谢谢。谢谢你的及时回复,但我仍然面临同样的问题。这是我在(isSDPresent){image.attr(“src”,Environment.getExternalStorageDirectory()时更改的代码部分+“/rreadyreckoner_images/download-r.png”);}else{image.attr(“src”),“/storage/emulated/0/rreadyreckoner_images/download-r.png”);}@anup尝试使用建议的方法并告诉结果!:)非常感谢@Elenasys只需更改这行字符串html=”"; 继续努力。
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setAllowFileAccess(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);

String imagePath = "file://"+ Environment.getExternalStorageDirectory().getAbsolutePath() + "rreadyreckoner_images/download-r.png";
//Create an html template.
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
//Load the image into your WebView:
mWebView.loadDataWithBaseURL("", html, "text/html","utf-8", "");