我使用Phonegap网站创建了一个网站并将其转换为Android应用程序。我有文件存储在华硕TF300平板电脑的本地存储器上,我需要一个应用程序来访问它们。要访问这些文件,我使用以下链接:
文件:///sdcard/original_img/3_1_5.jpg
现在有趣的部分。如果我在Chrome,Firefox或平板电脑上的任何其他浏览器中打开此链接,则图片会加载。但是如果我在index.html中启动一个具有相同链接的应用程序,则图像根本不会加载。
它可能是什么?对于应用程序和浏览器,存储路径是否有所不同?
答案 0 :(得分:1)
看起来您需要将其添加到您的应用AndroidManifest.xml中:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
聊天对话中的更新(based on this thread):
添加config.xml
:
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />
文件路径应如下所示:
file:///sdcard/<path>
答案 1 :(得分:0)
如果您使用上述程序您可能需要允许使用此行进行访问:
mWebView.getSettings()setAllowFileAccess(真);
或尝试使用此替代方法(在html中)
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file:/"+ base + "/original_img/3_1_5.jpg";
String strimg="<img src=\""+ imagePath + "\" alt=\"\" width=\"168\" height=\"120\" v:shapes=\Picture_x0020_421\" />";