简体   繁体   English

SecurityException:权限被拒绝(缺少 INTERNET 权限?)

[英]SecurityException: Permission denied (missing INTERNET permission?)

this error is really really really strange and I don't know how to reproduce it and how to fix it because I made a lot of searches but nothing was useful.这个错误真的真的很奇怪,我不知道如何重现它以及如何修复它,因为我进行了大量搜索,但没有任何用处。

Here's the stacktrace:这是堆栈跟踪:

Stack Trace
_________________________________
0   java.lang.RuntimeException: An error occured while executing doInBackground()
1       at android.os.AsyncTask$3.done(AsyncTask.java:299)
2       at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
3       at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
4       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
5       at java.util.concurrent.FutureTask.run(FutureTask.java:137)
6       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
7       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
8       at java.lang.Thread.run(Thread.java:856)
9   Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
10      at java.net.InetAddress.lookupHostByName(InetAddress.java:430)
11      at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12      at java.net.InetAddress.getAllByName(InetAddress.java:214)
13      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
14      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
15      at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
16      at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
17      at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
18      at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
19      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
20      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
21      at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
22      at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
23      at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
24      at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
25      at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
26      at com.designfuture.music.api.MusixMatchApi.sendRequestJSON(MusixMatchApi.java:1143)
27      at com.designfuture.music.api.MusixMatchApi.handleRequestJSON(MusixMatchApi.java:982)
28      at com.designfuture.music.api.MusixMatchApi.getConfig(MusixMatchApi.java:211)
29      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:28)
30      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:1)
31      at android.os.AsyncTask$2.call(AsyncTask.java:287)
32      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
33      ... 4 more
34  Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
35      at libcore.io.Posix.getaddrinfo(Native Method)
36      at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
37      at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
38      ... 26 more
39  Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
40      ... 29 more
41  java.lang.SecurityException: Permission denied (missing INTERNET permission?)
42      at java.net.InetAddress.lookupHostByName(InetAddress.java:430)
43      at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
44      at java.net.InetAddress.getAllByName(InetAddress.java:214)
45      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
46      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
47      at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
48      at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
49      at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
50      at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
51      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
52      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
53      at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
54      at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
55      at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
56      at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
57      at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
58      at com.designfuture.music.api.MusixMatchApi.sendRequestJSON(MusixMatchApi.java:1143)
59      at com.designfuture.music.api.MusixMatchApi.handleRequestJSON(MusixMatchApi.java:982)
60      at com.designfuture.music.api.MusixMatchApi.getConfig(MusixMatchApi.java:211)
61      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:28)
62      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:1)
63      at android.os.AsyncTask$2.call(AsyncTask.java:287)
64      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
65      at java.util.concurrent.FutureTask.run(FutureTask.java:137)
66      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
67      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
68      at java.lang.Thread.run(Thread.java:856)
69  Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
70      at libcore.io.Posix.getaddrinfo(Native Method)
71      at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
72      at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
73      ... 26 more
74  Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
75      ... 29 more
76  libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
77      at libcore.io.Posix.getaddrinfo(Native Method)
78      at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
79      at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
80      at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
81      at java.net.InetAddress.getAllByName(InetAddress.java:214)
82      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
83      at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
84      at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
85      at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
86      at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
87      at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
88      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
89      at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
90      at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
91      at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
92      at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
93      at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
94      at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
95      at com.designfuture.music.api.MusixMatchApi.sendRequestJSON(MusixMatchApi.java:1143)
96      at com.designfuture.music.api.MusixMatchApi.handleRequestJSON(MusixMatchApi.java:982)
97      at com.designfuture.music.api.MusixMatchApi.getConfig(MusixMatchApi.java:211)
98      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:28)
99      at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:1)
100     at android.os.AsyncTask$2.call(AsyncTask.java:287)
101     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
102     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
103     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
104     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
105     at java.lang.Thread.run(Thread.java:856)
106 Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
107     ... 29 more
108 libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
109     at libcore.io.Posix.getaddrinfo(Native Method)
110     at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
111     at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
112     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
113     at java.net.InetAddress.getAllByName(InetAddress.java:214)
114     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
115     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
116     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
117     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
118     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
119     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
120     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
121     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
122     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
123     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
124     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
125     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:185)
126     at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
127     at com.designfuture.music.api.MusixMatchApi.sendRequestJSON(MusixMatchApi.java:1143)
128     at com.designfuture.music.api.MusixMatchApi.handleRequestJSON(MusixMatchApi.java:982)
129     at com.designfuture.music.api.MusixMatchApi.getConfig(MusixMatchApi.java:211)
130     at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:28)
131     at com.designfuture.music.asynctask.GetConfigAsyncTask.doInBackground(GetConfigAsyncTask.java:1)
132     at android.os.AsyncTask$2.call(AsyncTask.java:287)
133     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
134     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
135     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
136     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
137     at java.lang.Thread.run(Thread.java:856)

Here's my AndroidManifest.xml这是我的 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my_app_package"
    android:installLocation="auto"
    android:versionCode="my_version_code"
    android:versionName="my_version_name" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <uses-feature android:glEsVersion="0x00010001" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowTaskReparenting="true"
        android:debuggable="true"
        android:icon="@drawable/mxm_icon"
        android:label="@string/musicbrowserlabel"
        android:theme="@style/Theme.Music" >

        <!-- MY ACTIVITIES -->



    </application>

</manifest>

Please don't bother asking me if I have the correct INTERNET permission in my manifest because this app is in market since 2 years :P请不要问我清单中是否有正确的 INTERNET 权限,因为这个应用程序已经上市 2 年了:P

I've also noticed that (from Crittercism) all bugs are coming from Android 4.1.x version (JB).我还注意到(来自 Crittercism)所有错误都来自 Android 4.1.x 版本 (JB)。 I don't know if device are rooted or what (I can't see this information for the moment)我不知道设备是否已植根或什么(我暂时看不到此信息)

NOTE: I wrote this answer in Jun 2013, so it's bit dated nowadays.注意:我在 2013 年 6 月写了这个答案,所以现在有点过时了。 Many things changed in Android platform since version 6 (Marshmallow, released late 2015), making the whole problem more/less obsolete.自第 6 版(Marshmallow,2015 年末发布)以来,Android 平台中发生了许多变化,使整个问题或多或少都过时了。 However I believe this post can still be worth reading as general problem analysis approach example.但是我相信这篇文章作为一般问题分析方法的例子仍然值得一读。


Exception you are getting ( SecurityException: Permission denied (missing INTERNET permission?) ), clearly indicates that you are not allowed to do networking.你得到的异常( SecurityException: Permission denied (missing INTERNET permission?) ),清楚地表明你不被允许进行网络连接。 That's pretty indisputable fact.这是相当不争的事实。 But how can this happen?但这怎么会发生呢? Usually it's either due to missing <uses-permission android:name="android.permission.INTERNET" /> entry in your AndroidManifest.xml file or, as internet permission is granted at installation not at run time, by long standing, missed bug in Android framework that causes your app to be successfully installed, but without expected permission grant.通常是由于在您的AndroidManifest.xml文件中缺少<uses-permission android:name="android.permission.INTERNET" />条目,或者由于 Internet 权限是在安装而不是在运行时授予的,长期存在的错误在 Android 框架中,导致您的应用程序成功安装,但没有预期的权限授予。

My Manifest is correct, so how can this happen?我的 Manifest 是正确的,那么这怎么会发生呢?

Theoretically, presence of uses-permission in Manifest perfectly fulfills the requirement and from developer standpoint is all that's needed to be done to be able to do networking.从理论上讲,Manifest 中uses-permission存在完美地满足了要求,从开发人员的角度来看,这就是能够进行网络连接所需要做的一切。 Moreover, since permissions are shown to the user during installation, the fact your app ended installed on user's device means s/he granted what you asked for (otherwise installation is cancelled), so assumption that if your code is executed then all requested permissions are granted is valid.此外,由于在安装过程中向用户显示了权限,因此您的应用程序最终安装在用户的设备上这一事实意味着他/她授予了您的要求(否则安装将被取消),因此假设如果您的代码被执行,那么所有请求的权限都是授予是有效的。 And once granted, user cannot revoke the permission other way than uninstalling the app completely as standard Android framework (from AOSP) offers no such feature at the moment.并且一旦获得授权,用户除了完全卸载应用程序之外,无法撤销该权限,因为标准 Android 框架(来自 AOSP)目前不提供此类功能。

But things are getting more tricky if you also do not mind your app running on rooted devices too.但是,如果您也不介意在有root权限的设备上运行您的应用程序,事情就会变得更加棘手。 There're tools available in Google Play your users can install to control permission granted to installed apps at run-time - for example: Permissions Denied and others.您的用户可以在 Google Play 中安装一些工具来控制在运行时授予已安装应用的权限- 例如: 权限被拒绝等。 This can also be done with CyanogenMod , vendor brand (ie LG's) or other custom ROM , featuring various type of "privacy managers" or similar tools.这也可以通过CyanogenMod 、供应商品牌(即 LG 的)或其他定制 ROM 来完成,具有各种类型的“隐私管理器”或类似工具。

So if app is blocked either way, it's basically blocked intentionally by the user and if so, it is really more user problem in this case (or s/he do not understand what certain options/tools really do and what would be the consequences) than yours, because standard SDK (and most apps are written with that SDK in mind) simply does not behave that way.因此,如果应用程序以任何一种方式被阻止,它基本上是被用户故意阻止的,如果是这样,那么在这种情况下,这确实是更多的用户问题(或者他/他不明白某些选项/工具真正做了什么以及会产生什么后果)比你的,因为标准 SDK(大多数应用程序都是用那个 SDK 编写的)根本不会那样做。 So I strongly doubt this problem occurs on "standard", non-rooted device with stock (or vendor like Samsung, HTC, Sony etc) ROM.所以我强烈怀疑这个问题会出现在“标准”、非 root 的设备上,有库存(或三星、HTC、索尼等供应商)ROM。

I do not want to crash...我不想崩溃...

Properly implemented permission management and/org blocking must deal with the fact that most apps may not be ready for the situation where access to certain features is both granted and not accessible at the same time, as this is kind of contradiction where app uses manifest to request access at install time.正确实施权限管理和/组织阻止必须处理这样一个事实,即大多数应用程序可能还没有准备好访问某些功能的访问权限同时被授予和无法访问,因为这是一种矛盾,应用程序使用清单来在安装时请求访问。 Access control done right should must make all things work as before, and still limit usability using techniques in scope of expected behavior of the feature.正确的访问控制应该使所有事情都像以前一样工作,并且仍然在功能的预期行为范围内使用技术限制可用性。 For example, when certain permission is granted (ie GPS, Internet access) such feature can be made available from the app/user perspective (ie you can turn GPS on. or try to connect), the altered implementation can provide no real data - ie GPS can always return no coordinates, like when you are indoor or have no satellite "fix".例如,当授予某些权限(即 GPS、Internet 访问)时,可以从应用程序/用户的角度(即您可以打开 GPS 或尝试连接)使此类功能可用,更改后的实现无法提供真实数据 -即 GPS 始终无法返回任何坐标,例如当您在室内或没有卫星“修复”时。 Internet access can be granted as before, but you can make no successful connection as there's no data coverage or routing.可以像以前一样授予 Internet 访问权限,但由于没有数据覆盖或路由,因此无法成功连接。 Such scenarios should be expected in normal usage as well, therefore it should be handled by the apps already.在正常使用中也应该预料到这种情况,因此它应该已经由应用程序处理。 As this simply can happen during normal every day usage, any crash in such situation should be most likely be related to application bugs.由于这种情况可能发生在正常的日常使用中,因此这种情况下的任何崩溃很可能与应用程序错误有关。

We lack too much information about the environment on which this problem occurs to diagnose problem w/o guessing, but as kind of solution, you may consider using setDefaultUncaughtExceptionHandler() to catch such unexpected exceptions in future and ie simply show user detailed information what permission your app needs instead of just crashing.我们缺乏太多关于发生此问题的环境的信息来诊断问题而无需猜测,但作为一种解决方案,您可以考虑使用setDefaultUncaughtExceptionHandler()来捕获将来此类意外异常,即简单地向用户显示什么权限的详细信息您的应用需要而不仅仅是崩溃。 Please note that using this will most likely conflict with tools like Crittercism, ACRA and others, so be careful if you use any of these.请注意,使用它很可能会与 Crittercism、ACRA 等工具发生冲突,因此在使用这些工具时要小心。

Notes笔记

Please be aware that android.permission.INTERNET is not the only networking related permission you may need to declare in manifest in attempt to successfully do networking.请注意, android.permission.INTERNET并不是您可能需要在清单中声明以成功进行网络连接的唯一与网络相关的权限。 Having INTERNET permission granted simply allows applications to open network sockets (which is basically fundamental requirement to do any network data transfer).授予INTERNET权限只是允许应用程序打开网络套接字(这基本上是进行任何网络数据传输的基本要求)。 But in case your network stack/library would like to get information about networks as well, then you will also need android.permission.ACCESS_NETWORK_STATE in your Manifest (which is ie required by HttpUrlConnection client ( see tutorial ).但是,如果您的网络堆栈/库也想获取有关网络的信息,那么您还需要清单中的android.permission.ACCESS_NETWORK_STATE (即HttpUrlConnection客户端需要( 参见教程)。


Addendum (2015-07-16)附录 (2015-07-16)

Please note that Android 6 (aka Marshmallow) introduced completely new permission management mechanism called Runtime Permissions .请注意,Android 6(又名 Marshmallow)引入了名为Runtime Permissions 的全新权限管理机制。 It gives user more control on what permission are granted (also allows selective grant) or lets one revoke already granted permissions w/o need to app removal:它使用户可以更好地控制授予的权限(也允许选择性授予),或者让用户撤销已授予的权限,而无需删除应用程序:

This [...] introduces a new permissions model, where users can now directly manage app permissions at runtime.这 [...] 引入了一种新的权限模型,用户现在可以在运行时直接管理应用程序权限。 This model gives users improved visibility and control over permissions, while streamlining the installation and auto-update processes for app developers.该模型为用户提供了更好的可见性和对权限的控制,同时简化了应用程序开发人员的安装和自动更新过程。 Users can grant or revoke permissions individually for installed apps.用户可以单独授予或撤销已安装应用的权限。

However, the changes do not affect INTERNET or ACCESS_NETWORK_STATE permissions, which are considered "Normal" permissions.但是,这些更改不会影响INTERNETACCESS_NETWORK_STATE权限,它们被视为“正常”权限。 The user does not need to explicitly grant these permission.用户不需要明确授予这些权限。

See behavior changes description page for details and make sure your app will behave correctly on newer systems too.有关详细信息,请参阅行为更改描述页面,并确保您的应用程序也能在较新的系统上正确运行。 It's is especially important when your project set targetSdk to at least 23 as then you must support new permissions model ( detailed documentation ).当您的项目将targetSdk设置为至少23时,这一点尤为重要,因为您必须支持新的权限模型( 详细文档)。 If you are not ready, ensure you keep targetSdk to at most 22 as this ensures even new Android will use old permission system when your app is installed.如果您还没有准备好,请确保将targetSdk保持为最多22因为这可以确保即使是新的 Android 在您的应用程序安装时也会使用旧的权限系统。

Be sure that the place where you adding请确保您添加的地方

<uses-permission android:name="android.permission.INTERNET"/>

is right.是正确的。

You should write it like that in AndroidManifest.xml :你应该在 AndroidManifest.xml 中这样写:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.project"> 
<uses-permission android:name="android.permission.INTERNET"/>

Dont make my mistakes :)不要犯我的错误:)

Android Studio 1.3b1 (not sure about other versions) autocompleted my internet permission to ANDROID.PERMISSION.INTERNET . Android Studio 1.3b1(不确定其他版本)自动完成了我对ANDROID.PERMISSION.INTERNET互联网权限。 Changing it to android.permission.INTERNET fixed the issue.将其更改为android.permission.INTERNET解决了该问题。

Add to manifest file the line:在清单文件中添加以下行:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

It fixed it for me.它为我修好了。

I resolved this error, I was adding permissions inside Application tag by mistake.我解决了这个错误,我错误地在 Application 标签中添加了权限。 I putted outside and it works fine.我把它放在外面,效果很好。 Hope it helps for someone.希望它对某人有帮助。

I also had this problem.我也有这个问题。 it was weird that it worked on my lollipop emulator, but not on my actual kitkat device.奇怪的是它可以在我的棒棒糖模拟器上运行,但不能在我的实际 kitkat 设备上运行。

Android Studio will now force you to write the permission upper case, and that's the problem. Android Studio 现在会强制你写权限大写,这就是问题所在。

Add添加

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Above the application tab and it will work.在应用程序选项卡上方,它将起作用。

Write your permission before the application tag as given below.在下面给出的应用程序标签之前写下您的许可。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.someapp.sample">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

Put these permission outside the <application> tag preferable before the tag, I tried it and it works for me.将这些权限放在<application>标签之外,最好放在标签之前,我试过了,它对我有用。

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

if it was an IPv6 address, have a look at this: https://code.google.com/p/android/issues/detail?id=33046如果是 IPv6 地址,请查看: https : //code.google.com/p/android/issues/detail?id=33046

Looks like there was a bug in Android that was fixed in 4.3(?).看起来在 4.3(?) 中修复了 Android 中的一个错误。

Just like Tom mentioned.就像汤姆提到的那样。 When you start with capital A then autocomplete will complete it as.当您以大写字母A开头时,自动完成功能将按原样完成。

ANDROID.PERMISSION.INTERNET

When you start typing with a then autocomplete will complete it as当你开始输入a ,然后自动完成将完成它作为

android.permission.INTERNET

The second one is the correct one.第二个是正确的。

I spend hours looking for solution to this problem and none of the solution in the answers worked.我花了几个小时寻找这个问题的解决方案,但答案中的解决方案都没有奏效。 Then I found out that I accidentally added a space during autocomplete between android.permission.INTERNET and "然后我发现我在android.permission.INTERNET"之间的自动完成期间不小心添加了一个空格"

Well it's a very confusing kind of bug.嗯,这是一种非常令人困惑的错误。 There could be many reasons:可能有很多原因:

  1. You are not mentioning the permissions in right place.您没有在正确的地方提到权限。 Like right above application.就像上面的应用程序一样。
  2. You are not using small letters.您没有使用小写字母。
  3. In some case you also have to add Network state permission.在某些情况下,您还必须添加网络状态权限。
  4. One which was my case there are some blank lines in manifest lines.我的情况之一是清单行中有一些空行。 Like there might be a blank line between permission tag and application line.就像权限标签和应用程序行之间可能有一个空行。 Remove them and you are done.删除它们,你就完成了。 Hope it will help希望它会有所帮助

在您的清单文件中删除它

 xmlns:tools="http://schemas.android.com/tools"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.SecurityException:权限被拒绝(缺少 INTERNET 权限?) - java.lang.SecurityException: Permission denied (missing INTERNET permission?) SecurityException:在棒棒糖上安装时,权限被拒绝(缺少INTERNET权限?) - SecurityException: Permission denied (missing INTERNET permission?) while installing on lollipop java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?),即使在android清单中添加了此权限 - java.lang.SecurityException: Permission denied (missing INTERNET permission?) even with adding this permission in android manifest 权限被拒绝(缺少 INTERNET 权限) - Permission denied (missing INTERNET permission) 权限被拒绝 - 缺少INTERNET权限? - Permission denied - missing INTERNET permission? 权限被拒绝(缺少INTERNET权限?):但是获得了许可 - Permission denied (missing INTERNET permission?): But permission is given 捕获的异常:java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?) - Caught exception: java.lang.SecurityException: Permission denied (missing INTERNET permission?) NetworkDispatcher.run:未处理的异常java.lang.SecurityException:权限被拒绝(缺少INTERNET权限?) - NetworkDispatcher.run: Unhandled exception java.lang.SecurityException: Permission denied (missing INTERNET permission?) 权限被拒绝(缺少Internet权限?)-Android错误 - Permission denied (missing INTERNET permission?) - android error AsyncTask权限被拒绝(缺少INTERNET权限?) - AsyncTask Permission denied (missing INTERNET permission?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM