SecurityException : 권한이 거부되었습니다 (인터넷 권한이 없습니까?)
이 오류는 정말 정말 이상합니다. 검색을 많이했지만 유용하지 않았기 때문에 재현 방법과 수정 방법을 모르겠습니다.
다음은 스택 추적입니다.
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)
여기 내 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>
이 앱은 2 년 이후로 출시되었으므로 매니페스트에 올바른 인터넷 권한이 있는지 묻지 마세요.
또한 모든 버그가 Android 4.1.x 버전 (JB)에서 발생하는 것으로 나타났습니다. 기기가 루팅되었는지 또는 무엇인지 모르겠습니다 (현재이 정보를 볼 수 없습니다).
NOTE: I wrote this answer in Jun 2013, so it's now bit dated. Some things changed in Android since version 6 (Marshmallow) of the platform since then, making the whole problem more/less obsolete nowadays. However I believe this post can still be worth reading as general problem analysis example, so I hope you can still find it educational.
Exception you are getting (SecurityException: Permission denied (missing INTERNET permission?)
), clearly indicates that you are not allowed to do networking. 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.
My Manifest is correct, so how can this happen?
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. 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.
But things are getting more tricky if you also do not mind your app running on rooted devices too. 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. This can also be done with CyanogenMod, vendor brand (i.e. LG's) or other custom ROM, featuring various type of "privacy managers" or similar tools.
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. So I strongly doubt this problem occurs on "standard", non-rooted device with stock (or vendor like Samsung, HTC, Sony etc) 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 (i.e. GPS, Internet access) such feature can be made available from the app/user perspective (i.e. you can turn GPS on. or try to connect), the altered implementation can provide no real data - i.e. GPS can always return no coordinates, like when you are indoor or have no satellite "fix". Internet access can granted as before, but you can make no successful connection as there's no data coverage or routing. 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 i.e. simply show user detailed information what permission your app needs instead of just crashing. 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.
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. Having INTERNET
permission granted simply allows applications to open network sockets (which is basically fundamental requirement to do any network data transfer). 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 i.e. required by HttpUrlConnection client (see tutorial).
Addendum (2015-07-16)
Please note that Android 6 (aka Marshmallow) introduced completely new permission management mechanism called 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. 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). 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.
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 :
<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
. Changing it to android.permission.INTERNET
fixed the issue.
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. 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.
Android Studio will now force you to write the permission upper case, and that's the problem.
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.
<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
Looks like there was a bug in Android that was fixed in 4.3(?).
Just like Tom mentioned. When you start with capital A
then autocomplete will complete it as.
ANDROID.PERMISSION.INTERNET
When you start typing with a
then autocomplete will complete it as
android.permission.INTERNET
The second one is the correct one.
Well it's a very confusing kind of bug. There could be many reasons:
- You are not mentioning the permissions in right place. Like right above application.
- You are not using small letters.
- In some case you also have to add Network state permission.
- 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
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 "
remove this in your manifest file
xmlns:tools="http://schemas.android.com/tools"
'IT박스' 카테고리의 다른 글
JavaScript에서 부모 요소 만 제거하고 자식 요소는 제거하지 않는 방법? (0) | 2020.09.13 |
---|---|
bash로 디렉토리가 마운트되었는지 확인하십시오. (0) | 2020.09.13 |
전체 WDK없이 windbg를 받고 있습니까? (0) | 2020.09.13 |
최대 2 개의 숫자를 찾으려면 어떻게합니까? (0) | 2020.09.13 |
Django "login ()은 정확히 1 개의 인수 (2 개)"오류를받습니다. (0) | 2020.09.13 |