Android webview loadDataWithBaseURL how load images from assets?

前端 未结 4 1498
花落未央
花落未央 2020-12-03 05:41

In my project I have a files:

\"MyProject/assets/folder1/image1.jpg\"
\"MyProject/assets/folder1/index.html\".

In webView I need to open i

4条回答
  •  孤街浪徒
    2020-12-03 06:24

    try to like this

    try {
                String filePath = null;
                filePath = "Your File path";
                Bitmap bitmap = null;
    
                bitmap = BitmapFactory.decodeFile(filePath);
                Log.v("Image data-->", "" + bitmap);
                imageWidth = bitmap.getWidth();
                imageHeight = bitmap.getHeight();
                Log.e("Width", "" + imageWidth);
                filePath = "file://" + filePath;
                String html = ""
                        + getDivTag(mapList)
                        + "";
    
                Log.v("MIS", "" + html);
                webview.getSettings().setSupportZoom(true);
                webview.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
    
                System.out.println(html);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    

提交回复
热议问题