Android ICS 上的 ACCESS_NETWORK_STATE 权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12778168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ACCESS_NETWORK_STATE permission on Android ICS
提问by Nguyen Minh Binh
I declared the permission ACCESS_NETWORK_STATE
in Application manifest as below.
我ACCESS_NETWORK_STATE
在应用程序清单中声明了权限,如下所示。
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Everything is good on Android 2.x. But on Android ICS, it failed with below log cat.
在 Android 2.x 上一切都很好。但在 Android ICS 上,它失败并显示以下日志猫。
java.lang.SecurityException: ConnectivityService: Neither user 10093
nor current process has android.permission.ACCESS_NETWORK_STATE. at
android.os.Parcel.readException(Parcel.java:1327) at
android.os.Parcel.readException(Parcel.java:1281) at
android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:663)
at
android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:455)
at com.tapfortap.AdView.getNetwork(AdView.java:146) at
com.tapfortap.AdView.loadAdsWithAppId(AdView.java:133) at
com.tapfortap.AdView.access0(AdView.java:47) at
com.tapfortap.AdView.run(AdView.java:88) at
android.os.Handler.handleCallback(Handler.java:605) at
android.os.Handler.dispatchMessage(Handler.java:92) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:4503) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) at
dalvik.system.NativeStart.main(Native Method)
回答by Nguyen Minh Binh
I updated the permissions like this and it works.
我更新了这样的权限并且它有效。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
this is because ACCESS_NETWORK_STATE is used as connectivityManger and this needs INTERNET connection.
这是因为 ACCESS_NETWORK_STATE 用作连接管理器,这需要 INTERNET 连接。
回答by user2259744
I believe this is an issue with Eclipse; it fails to refresh the manifest to load the permission.
我相信这是 Eclipse 的问题;它无法刷新清单以加载权限。
I had the same problem as the original poster and solved it by adding the permission a second time--but then I was able to remove the permission without affecting behavior. This makes me suspect that Eclipse didn't load permissions correctly until I touched the file.
我遇到了与原始海报相同的问题,并通过第二次添加权限解决了这个问题——但后来我能够在不影响行为的情况下删除权限。这让我怀疑 Eclipse 在我触摸文件之前没有正确加载权限。
回答by Waleed A. Elgalil
Just add the below permission and it will work fine, i had this a problem before and resolved with me
只需添加以下权限,它就可以正常工作,我以前遇到过这个问题并与我一起解决
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
回答by Nguyen Gia Tu
Uh-oh,If u adding by default,it will be:
嗯,如果你默认添加,它将是:
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE"/>
if u re-add permission by:
如果您通过以下方式重新添加权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
It works fine. Unbelievable ! It costs me 2 days
它工作正常。逆天 !我花了2天
回答by S HemaNandhini
you are missing the Internet permission.add this permisssion it will correct your problem
您缺少 Internet 权限。添加此权限将解决您的问题
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
回答by ivan_onys
Clean and then Build project solved the issue for me.
Clean 然后 Build 项目为我解决了这个问题。
回答by Raghavendra
Clean Project. Check the manifest file. Some package name changes or misplaced data may causes this error.
清洁项目。检查清单文件。某些包名称更改或错放的数据可能会导致此错误。
Clean the project will work.
清理项目将起作用。
回答by Vinoj John Hosan
Just cut the <uses-permission android:name="android.permission.INTERNET" />
and paste all the above permissions. It will work fine...
只需剪切<uses-permission android:name="android.permission.INTERNET" />
并粘贴上述所有权限。它会工作得很好...
回答by devDeejay
In your code, There would be places where you would be checking the Internet Availability before making your calls so that your app doesn't crash at runtime. For that, you have to access the 'NETWORK STATE' which requires the permission :
在您的代码中,您会在调用之前检查 Internet 可用性,以便您的应用程序不会在运行时崩溃。为此,您必须访问需要权限的“网络状态”:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And when the Internet is available, your device communicates with the server using the 'INTERNET' which requires the permission :
并且当 Internet 可用时,您的设备使用需要许可的“ INTERNET”与服务器通信:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />
回答by Divya Gupta
In my case, neither Clean Projectnot Rebuild Projectworked, and I spent hours to figure out how to get rid of this lint error.
就我而言,Clean Project和Rebuild Project都不起作用,我花了几个小时来弄清楚如何摆脱这个 lint 错误。
I was also afraid to use the final option Invalidate Caches and Restartbecause I might roll back to any Local History of a file in future, in case any bug arises.
我也害怕使用最后一个选项Invalidate Caches and Restart因为我可能会在将来回滚到文件的任何本地历史记录,以防出现任何错误。
So finally, I opted for the following option.
所以最后,我选择了以下选项。
- I chose File->Invalidate Caches and Restart.
- It opened a popup. I then selected the option Just Restart.
- 我选择了File->Invalidate Caches and Restart。
- 它打开了一个弹出窗口。然后我选择了Just Restart选项。
And guess what!!It solved my problem. So if any of you are still struggling to get rid of this error, you might wanna try my solution. Do let me know if it worked.
你猜怎么着!它解决了我的问题。因此,如果你们中的任何人仍在努力摆脱此错误,您可能想尝试我的解决方案。请让我知道它是否有效。