gpt4 book ai didi

android - 在 webview 中加载保存在 sdcard 中的图像

转载 作者:IT老高 更新时间:2023-10-28 23:17:33 25 4
gpt4 key购买 nike

使用以下代码

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = base + "/test.jpg";
mWebView.loadUrl(imagePath);

图片未加载...

也试过

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = base + "/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadData(html, "text/html","utf-8");

请帮忙

最佳答案

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html","utf-8", "");

这成功了,因为我们必须在任何文件之前附加“前缀“file://”以便在 webview 中显示

关于android - 在 webview 中加载保存在 sdcard 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5051364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com