Android:Webview加载网址失败?

问题描述:

我能够运行复制文件和文件夹从一个目录到另一个,我有ff.input代码:Android:Webview加载网址失败?

来源:新文件(Environment.getExternalStorageDirectory(),“E_BU/EngagiaDroid”),这也是我的设备上输出到/ mnt/SD卡/ E_BU/EngagiaDroid,AND, 目标:新建文件(Environment.getExternalStorageDirectory(), “EngagiaDroid”),这也是我的设备上输出到/ mnt/SD卡/ EngagiaDroid

然而,当我用webview code in this link使用,以查看我的HTML:Environment.getExternalStorageDirectory()+这给输出 “/EngagiaDroid/videos.html” /mnt/sdcard/EngagiaDroid/videos.htmlwebview无法加载该网址。但是,当我将网址更改为其他网址(例如 http://codeofaninja.blogspot.com/2011/05/how-to-view-webpage-inside-your-android.html)时,它能够加载,这意味着网页视图代码有效。

我确定这些文件已被复制。

我假设你有READ_EXTERNAL_STORAGE权限。你在WebView上设置webView.getSettings().setAllowFileAccess(true);吗?

除此之外,最有可能的事情是URL的问题。首先应该从file:///开始。也许是这样的:

"file://" + Environment.getExternalStorageDirectory() + "/EngagiaDroid/videos.html" 

例子,我经常看到出来file:///sdcard/...

+0

哇!非常感谢Sven Viking!你指出的所有事情都使它对我有用。 :) – Kris 2011-05-26 05:34:32

+0

没问题:)。 – 2011-05-26 05:41:35

wView.loadUrl("file://sdcard/About_Eng.htm"); 

使用该L INE及其工作

+0

这可能在某些情况下有效,但它不再是当前设备上的真正路径(只是用于向后可计算性的符号链接),所以您应该查询设备的正确路径(如在公认的答案中),而不是对其进行硬编码。 – 2011-05-26 19:17:57