Android:Webview加载URL失败?
我能够运行将文件和文件夹从一个目录复制到另一个目录的代码,我有 ff.input:
Source: new File(Environment.getExternalStorageDirectory(), "E_BU/EngagiaDroid") ,它给出输出 /我的设备上的 mnt/sdcard/E_BU/EngagiaDroid,并且, 目的地: new File(Environment.getExternalStorageDirectory(), "EngagiaDroid") 在我的设备上提供输出 /mnt/sdcard/EngagiaDroid 。
但是,当我使用 webview 代码时使用此链接查看我的html:Environment.getExternalStorageDirectory() + "/EngagiaDroid/videos.html" 给出输出 /mnt/sdcard/EngagiaDroid/videos.html,webview 无法加载该 url。但是当我将网址更改为其他网址时 http://codeofaninja.blogspot.com /2011/05/how-to-view-webpage-inside-your-android.html,它能够加载,这意味着 webview 代码可以工作。
我确信文件已被复制。
I am able to run a code that copies files and folders from one directory to another, I have the ff.input:
Source: new File(Environment.getExternalStorageDirectory(), "E_BU/EngagiaDroid") which gives the output /mnt/sdcard/E_BU/EngagiaDroid on my device, AND,
Destination: new File(Environment.getExternalStorageDirectory(), "EngagiaDroid") which gives the output /mnt/sdcard/EngagiaDroid on my device.
However, when I used the webview code in this link to view my html using: Environment.getExternalStorageDirectory() + "/EngagiaDroid/videos.html"
which gives the output /mnt/sdcard/EngagiaDroid/videos.html, webview was not able to load that url. But when I change the url to other url for example
http://codeofaninja.blogspot.com/2011/05/how-to-view-webpage-inside-your-android.html, it was able to load, meaning the webview code works.
I'm sure that the files were copied.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您具有 READ_EXTERNAL_STORAGE 权限。您是否在 WebView 上设置了
webView.getSettings().setAllowFileAccess(true);
?除此之外,最有可能的是 URL 的问题。一方面,它应该以
file:///
开头。也许是这样的:我经常看到的例子出现在
file:///sdcard/...
I assume you have the READ_EXTERNAL_STORAGE permission. Have you set
webView.getSettings().setAllowFileAccess(true);
on the WebView?Other than that, the most likely thing would be a problem with the URL. It should start with
file:///
, for one thing. Maybe something like:Examples I've seen often come out to
file:///sdcard/...
用这个l
ine 及其工作
Use this l
ine and its work