Android ConnectivityManager is not seeing permission ACCESS_NETWORK_STATE

Danubian Sailor picture Danubian Sailor · Feb 21, 2012 · Viewed 11.9k times · Source

I have simple code that wants to read the state of network connection. I've added permission to the AndroidManifest.xml:

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

My code that tries to access network state:

    ConnectivityManager conmgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ninfo = conmgr.getActiveNetworkInfo();

And the error that is thrown:

 E/AndroidRuntime(7650): java.lang.SecurityException: ConnectivityService: Neither user 10080 nor current process has android.permission.ACCESS_NETWORK_STATE.

I've long tried to find any error, but everything seems to be spelled correctly. It seems like the new version of AndroidManifest is not deployed to device. I've tried to clean project in Eclipse, uninstall app from phone, but nothing is working, I get the same communicate again. What I'm doing wrong?

Answer

MobileCushion picture MobileCushion · Feb 21, 2012

I think it is

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

instead of

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