Java 未将SD卡中的图像加载到WebView中
我将以下HTML代码加载到Java 未将SD卡中的图像加载到WebView中,java,android,android-webview,filenotfoundexception,android-external-storage,Java,Android,Android Webview,Filenotfoundexception,Android External Storage,我将以下HTML代码加载到字符串中 <html> <body> <img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page1.jpg"/> <img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page2.jpg"/>
字符串中
<html>
<body>
<img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page1.jpg"/>
<img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page2.jpg"/>
<img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page3.jpg"/>
<img style="width:100%" src="file://storage/emulated/0/sdcard/Download/Page4.jpg"/>
</body>
</html>
我在AndroidManifest.xml
中拥有以下权限,并确保已授予这些权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
下面是WebView
尝试加载图像时的情况
提前感谢您的时间 我没有使用
环境。getExternalStorageDirectory
而是使用了/sdcard/Downloads
,这似乎解决了问题。因此,我生成的最终有效的HTML如下所示
<html>
<body>
<img style="width:100%" src="file://sdcard/Download/Page1.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page2.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page3.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page4.jpg"/>
</body>
</html>
在我的例子中,编辑html图像路径字符串basePath=Environment.getExternalStorageDirectory().getAbsolutePath().toString()时加载的图像;字符串imagePath=“file://“+basePath+”/test.jpg”;您可以使用imagePath动态编辑html文件文本。src=”file://storage/emulated/0/sdcard/Download/Page1.jpg“
要让它工作,它应该是src=”file:///storage/emulated/0/sdcard/Download/Page1.jpg“
/storage/simulated/0/sdcard/Download/Page1.jpg
这是一条不可能的路径。这也与可移动微型SD卡无关。您可以使用FIle类检查该路径中是否不存在该文件。尝试File File=new文件(“/storage/emulated/0/sdcard/Download/Page1.jpg”);如果(file.existst()){…}else{…}
/storage/emulated/0/sdcard/Download/Page1.jpg
您可能已成功使用/storage/emulated/0/Download/Page1.jpg
W/cr_CrashFileManager: /data/user/0/com.example.myapp/cache/WebView/Crash Reports does not exist or is not a directory
<html>
<body>
<img style="width:100%" src="file://sdcard/Download/Page1.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page2.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page3.jpg"/>
<img style="width:100%" src="file://sdcard/Download/Page4.jpg"/>
</body>
</html>