eclipse Android ConnectivityManager 没有看到权限 ACCESS_NETWORK_STATE

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9375763/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:45:29  来源:igfitidea点击:

Android ConnectivityManager is not seeing permission ACCESS_NETWORK_STATE

androideclipseandroid-networkingeclipse-adt

提问by Danubian Sailor

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

我有想要读取网络连接状态的简单代码。我已经为 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?

我一直试图找出任何错误,但一切似乎都拼写正确。新版本的 AndroidManifest 似乎没有部署到设备上。我试图在 Eclipse 中清理项目,从手机上卸载应用程序,但没有任何效果,我再次获得相同的通信。我做错了什么?

回答by MobileCushion

I think it is

我觉得是这样的

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

instead of

代替

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