Android WebView 是否需要打开外部 URL 的权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/196946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Android WebView need permissions for opening external URLs?
提问by Tahir Akhtar
I was trying the following example, but with external URLs: Using WebViews
我正在尝试以下示例,但使用外部 URL: 使用 WebViews
The example shows how to load an HTML file from assets folder (file:// url
) and display it in a WebView.
该示例展示了如何从资产文件夹 ( file:// url
)加载 HTML 文件并将其显示在 WebView 中。
But when I try it with external URLs (like http://google.com), I am always getting a "Website Not Available" error. Android's built-in browser is able to access all external URLs.
但是当我尝试使用外部 URL(如http://google.com)时,我总是收到“网站不可用”错误。Android 的内置浏览器能够访问所有外部 URL。
I suspect that it has something to do with permissions, but wasn't able to confirm it.
我怀疑它与权限有关,但无法确认。
回答by Tahir Akhtar
I found out the answer myself.
我自己找到了答案。
The permission name is android.permission.INTERNET.
权限名称是 android.permission.INTERNET。
Adding following line to the AndroidManifest.xml (nested directly in tag) did the trick:
将以下行添加到 AndroidManifest.xml(直接嵌套在标签中)可以解决问题:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
The file can also be edited graphically in Eclipse plugin through permissions tab.
该文件也可以通过权限选项卡在 Eclipse 插件中以图形方式编辑。
回答by Tahir Akhtar
It's a user permission:
这是用户权限:
<uses-permission android:name="android.permission.INTERNET" />