簡體   English   中英

Android:將圖像從本地存儲加載到webview

[英]Android: load image from local storage to webview

我下載圖像並存儲在本地存儲中。 我從本地存儲的html文件加載此圖像。
<img src="file:///data/data/com.example/imagefiles/photo.jpg"/>

我從WebView加載html文件。 webView.loadUrl("file:///android_asset/show_download_image.html"); 但圖像沒有顯示。 我確信下載圖像是成功的。 我想知道是否可以將圖像從本地存儲加載到html文件中,或者有沒有辦法從本地加載圖像?

謝謝。

為什么不嘗試直接加載圖像,如下所示:

String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/photo.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
webView.loadDataWithBaseURL("", html, "text/html","utf-8", ""); 

這里的圖像是SD卡。 您也可以更改用於在資產中保留圖像的代碼。

檢查你的webview javaScriptEnabled是真的嗎?

   WebView.getSettings().setJavaScriptEnabled(true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM