我需要什么权限才能从 Android 应用程序访问互联网?
运行我的应用程序时出现以下异常:
java.net.SocketException: Permission denied (maybe missing INTERNET permission)
如何解决缺少权限问题?
I get the following Exception running my app:
java.net.SocketException: Permission denied (maybe missing INTERNET permission)
How do I solve the missing permission problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
将 INTERNET 权限添加到清单文件中。
您必须添加此行:
在 AndroidManifest.xml 中的
application
标记之外Add the INTERNET permission to your manifest file.
You have to add this line:
outside the
application
tag in your AndroidManifest.xml只需将其放在上面,如下所示
just put above line like below
如果您想在应用程序中使用互联网并检查网络状态,即应用程序是否已连接到互联网,那么您必须在
application
标记之外使用以下代码。对于 Internet 权限:
对于访问网络状态:
完整代码:
If you want using Internet in your app as well as check the network state i.e. Is app is connected to the internet then you have to use below code outside of the
application
tag.For Internet Permission:
For Access network state:
Complete Code:
即使使用我也遇到了同样的问题
如果您想使用
http
而不是https
连接 Web api 。也许您使用的 Android 设备采用 Android 9 (Pie) 或 API 级别 28 或更高版本。android:usesCleartextTraffic
默认值为false
。你必须设置为最后,应该是
https
https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
I had the same problem even use
<uses-permission android:name="android.permission.INTERNET" />
If you want connect web api using
http
nothttps
. Maybe you use android device using Android 9 (Pie) or API level 28 or higher .android:usesCleartextTraffic
default value isfalse
. You have to set beFinally, should be
https
https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic
如果只是使用互联网,则使用 -
如果您正在获取互联网状态,则也使用 -
就在应用程序标签上方。
if just using internet then use-
if you are getting the state of internet then use also -
just above the application tag.
使用这些:
Use these:
忘记将权限添加到清单中
添加此代码作为方法
并将其写入您的Main
forget about adding the permission into the manifest
Add this code as a method
and write this in your Main