开发者社区> 问答> 正文

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>

展开
收起
游客bnlxddh3fwntw 2020-04-23 19:20:10 751 0
1 条回答
写回答
取消 提交回答
  • 你得到SecurityException: Permission denied (missing INTERNET permission?),明确表示不允许你进行联网。这是一个不争的事实。但这怎么可能发生呢?通常是因为在你的AndroidManifest.xml文件中缺少 ,或者,由于互联网许可是在安装时授予的,而不是在运行时,由于长期存在,Android框架中漏掉了导致应用程序成功安装的错误,但没有预期的权限授予。

    我的Manifest是正确的,那么这怎么会发生呢?

    理论上uses-permission在Manifest中,完美地满足了需求,从开发人员的角度来看,能够进行联网所需做的就是全部。此外,由于在安装过程中向用户显示了权限,因此你的应用程序在用户设备上安装的事实意味着授予你所要求的权限(否则安装将被取消),因此假设如果你的代码被执行,那么所有请求的权限都被授予是有效的。一旦获得批准,用户除了完全卸载应用程序之外,还不能取消许可,因为标准的Android框架(来自AOSP)目前没有这样的功能。

    你可以考虑使用setDefaultUncoghtExceptionHandler()为了在将来捕捉到这样的意外异常,只需向用户显示你的应用程序需要什么样的权限,而不是仅仅是崩溃。

    注记

    请注意android.permission.INTERNET并不是在清单中声明的唯一与网络相关的权限。有INTERNET授予的权限只允许应用程序打开网络套接字(这基本上是进行任何网络数据传输的基本要求)。但是,如果你的网络堆栈/库也想获得有关网络的信息,那么你也需要android.permission.ACCESS_NETWORK_STATE在你的报表中。

    增编(2015-07-16)

    请注意,android 6(又名marshmlow)引入了全新的权限管理机制,名为运行时权限。它允许用户更多地控制所授予的权限(还允许有选择的授予),或者让用户撤销已经授予的权限,以便删除应用程序。

    然而,这些变化并不影响互联网或接入网络状态权限,这些权限被认为是“正常”权限。用户不需要显式授予这些权限。

    2020-04-23 19:20:24
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载