gpt4 book ai didi

android - 安全异常 : Permission denied (missing INTERNET permission? )

转载 作者:IT老高 更新时间:2023-10-28 13:08:08 29 4
gpt4 key购买 nike

这个错误真的真的很奇怪,我不知道如何重现它以及如何修复它,因为我进行了大量搜索,但没有任何用处。

这是堆栈跟踪:

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>

请不要问我 list 中是否有正确的 INTERNET 权限,因为这个应用程序已经上市 2 年了:P

我还注意到(来自 Crittercism)所有错误都来自 Android 4.1.x 版本 (JB)。我不知道设备是否已 Root 或什么(我暂时看不到此信息)

最佳答案

注意:我在 2013 年 6 月写了这个答案,所以现在有点过时了。自第 6 版(Marshmallow,2015 年末发布)以来,Android 平台发生了许多变化,使整个问题或多或少都过时了。但是我相信这篇文章作为一般问题分析方法的例子仍然值得一读。

您得到的异常 ( SecurityException: Permission denied (missing INTERNET permission?) ),清楚地表明您不允许进行联网。这是相当不争的事实。但这怎么会发生呢?通常是由于缺少 <uses-permission android:name="android.permission.INTERNET" />您的 AndroidManifest.xml 中的条目文件,或者,由于 Internet 权限是在安装时而不是在运行时授予的,长期以来,Android 框架中遗漏的错误导致您的应用程序成功安装,但没有预期的权限授予。
我的 Manifest 是正确的,那么这怎么会发生呢?
理论上,存在 uses-permission在 Manifest 中完美地满足了要求,从开发人员的角度来看,这就是能够进行网络连接所需要做的一切。此外,由于在安装过程中向用户显示了权限,因此您的应用程序最终安装在用户的设备上这一事实意味着他/她授予了您的要求(否则安装将被取消),因此假设如果您的代码被执行,那么所有请求的权限都是授予是有效的。并且一旦被授予,用户除了完全卸载应用程序之外,不能撤销该权限,因为标准 Android 框架(来自 AOSP)目前不提供此类功能。
但是,如果您也不介意在 rooted 上运行您的应用程序,事情就会变得更加棘手。设备也是。您的用户可以安装 Google Play 中的工具来控制授予已安装应用的权限 在运行时 - 例如:Permissions Denied和其他人。这也可以通过 CyanogenMod 来完成、供应商品牌(即 LG)或 other custom ROM ,具有各种类型的“隐私管理器”或类似工具。
因此,如果应用程序以任何一种方式被阻止,它基本上是被用户故意阻止的,如果是这样,在这种情况下,这确实是更多的用户问题(或者他/他不明白某些选项/工具真正做了什么以及会产生什么后果)比你的,因为标准 SDK(大多数应用程序都是用该 SDK 编写的)根本不会那样做。所以我强烈怀疑这个问题发生在“标准”、非 root 的设备上,有库存(或三星、HTC、索尼等供应商)ROM。
我不想崩溃...
正确实现权限管理和/组织阻止必须处理这样一个事实,即大多数应用程序可能还没有准备好访问某些功能的访问权限同时被授予和无法访问,因为这是一种矛盾,应用程序使用 list 来在安装时请求访问。正确的访问控制应该使所有事情都像以前一样工作,并且仍然在功能的预期行为范围内使用技术限制可用性。例如,当授予某些权限(即 GPS、互联网访问)时,可以从应用程序/用户的角度(即您可以打开 GPS 或尝试连接)使此类功能可用,更改后的实现无法提供真实数据 -即 GPS 始终无法返回任何坐标,例如当您在室内或没有卫星“修复”时。可以像以前一样授予 Internet 访问权限,但由于没有数据覆盖或路由,因此无法成功连接。在正常使用中也应该预料到这种情况,因此它应该已经由应用程序处理。由于这种情况可能发生在正常的日常使用中,因此在这种情况下的任何崩溃很可能与应用程序错误有关。
我们缺乏关于发生此问题的环境的太多信息来诊断问题而无需猜测,但作为一种解决方案,您可以考虑使用 setDefaultUncaughtExceptionHandler()将来捕获此类意外异常,即简单地向用户显示您的应用程序需要什么权限的详细信息,而不仅仅是崩溃。请注意,使用它很可能会与 Crittercism、ACRA 等工具发生冲突,因此在使用这些工具时要小心。
备注
请注意 android.permission.INTERNET不是您可能需要在 list 中声明以尝试成功进行网络的唯一网络相关权限。有 INTERNET授予的权限只是允许应用程序打开网络套接字(这基本上是进行任何网络数据传输的基本要求)。但是,如果您的网络堆栈/库也想获取有关网络的信息,那么您还需要 android.permission.ACCESS_NETWORK_STATE在您的 list 中(即 HttpUrlConnection 客户端( see tutorial )要求。

附录 (2015-07-16)
请注意,Android 6(又名 Marshmallow)引入了名为 的全新权限管理机制。运行时权限 .它使用户可以更好地控制授予的权限(也允许选择性授予),或者让用户撤销已授予的权限,而无需删除应用程序:

This [...] introduces a new permissions model, where users can nowdirectly manage app permissions at runtime. This model gives usersimproved visibility and control over permissions, while streamliningthe installation and auto-update processes for app developers. Userscan grant or revoke permissions individually for installed apps.


但是,这些更改不会影响 INTERNETACCESS_NETWORK_STATE权限,被视为“正常”权限。用户不需要明确授予这些权限。
behavior changes description详细信息页面,并确保您的应用程序在较新的系统上也能正常运行。当您的项目设置 targetSdk 时,这一点尤为重要。至少到 23和你一样 必须支持新的权限模型 ( detailed documentation )。如果您还没有准备好,请确保保留 targetSdk至多 22因为这可以确保即使是新的 Android 在您的应用程序安装时也会使用旧的权限系统。

关于android - 安全异常 : Permission denied (missing INTERNET permission? ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17360924/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com