11

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?

Danubian Sailor
  • 1
  • 38
  • 145
  • 223

2 Answers2

23

I think it is

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

instead of

<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
MobileCushion
  • 7,065
  • 7
  • 42
  • 62
  • Yes, of course it was it, I was looking at permission string, I thought there is any validation of AndroidManifest.xml, but obviously I was wrong. – Danubian Sailor Feb 21 '12 at 10:38
  • 1
    I'm confuse of : does this resolved your problem? in my search, there is not `user-permission` in android. – VinceStyling Dec 11 '15 at 03:12
  • 1
    @VinceStyling you need to have a file called AndroidManifest.xml and in there . The OP misspelled uses and wrote user instead – verunar Dec 01 '20 at 10:31
0

Delete the imports of all kinds that has to do with NetworkInfo like Java.net packages or any other.. Re-import

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30511411) – MD. RAKIB HASAN Dec 07 '21 at 13:15