Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.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/9/javascript/469.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
Java 未将SD卡中的图像加载到WebView中_Java_Android_Android Webview_Filenotfoundexception_Android External Storage - Fatal编程技术网

Java 未将SD卡中的图像加载到WebView中

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代码加载到
字符串中

<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>