ACCESS_NETWORK_STATE permission on Android ICS

2019-01-18 18:32发布

I declared the permission ACCESS_NETWORK_STATE in Application manifest as below.

<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.

 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.access$100(AdView.java:47) at
 com.tapfortap.AdView$1$1.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)

9条回答
仙女界的扛把子
2楼-- · 2019-01-18 19:07

Just cut the <uses-permission android:name="android.permission.INTERNET" /> and paste all the above permissions. It will work fine...

查看更多
The star\"
3楼-- · 2019-01-18 19:12

This should a bug of Android ICS framework. I just resolved this by add this permission again:

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

Unbelievable!.

查看更多
smile是对你的礼貌
4楼-- · 2019-01-18 19:25

I believe this is an issue with Eclipse; it fails to refresh the manifest to load the permission.

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.

查看更多
戒情不戒烟
5楼-- · 2019-01-18 19:26

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 :

<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 :

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

查看更多
仙女界的扛把子
6楼-- · 2019-01-18 19:28

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

查看更多
Viruses.
7楼-- · 2019-01-18 19:28

Clean Project. Check the manifest file. Some package name changes or misplaced data may causes this error.

Clean the project will work.

查看更多
登录 后发表回答