Nguyen  Minh Binh
Nguyen Minh Binh

Reputation: 24443

ACCESS_NETWORK_STATE permission on Android ICS

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)

Upvotes: 25

Views: 90933

Answers (10)

Nguyen  Minh Binh
Nguyen Minh Binh

Reputation: 24443

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.

Upvotes: 36

Divya Gupta
Divya Gupta

Reputation: 502

In my case, neither Clean Project not Rebuild Project worked, and I spent hours to figure out how to get rid of this lint error.

I was also afraid to use the final option Invalidate Caches and Restart because I might roll back to any Local History of a file in future, in case any bug arises.

So finally, I opted for the following option.

  1. I chose File->Invalidate Caches and Restart.
  2. It opened a popup. I then selected the option 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.

Upvotes: 0

devDeejay
devDeejay

Reputation: 6059

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" />

Upvotes: 1

S HemaNandhini
S HemaNandhini

Reputation: 333

you are missing the Internet permission.add this permisssion it will correct your problem

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

Upvotes: 2

Nguyen Gia Tu
Nguyen Gia Tu

Reputation: 21

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

Upvotes: 1

Waleed A. Elgalil
Waleed A. Elgalil

Reputation: 495

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" />

Upvotes: 10

Raghavendra
Raghavendra

Reputation: 2303

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

Clean the project will work.

Upvotes: 1

Vinoj John Hosan
Vinoj John Hosan

Reputation: 6873

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

Upvotes: 1

ivan_onys
ivan_onys

Reputation: 2382

Clean and then Build project solved the issue for me.

Upvotes: 3

user2259744
user2259744

Reputation: 111

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.

Upvotes: 11

Related Questions