摘录自http://www.cnblogs.com/haorenjie/archive/2012/09/12/2682655.html

public boolean checkNetwork() {
boolean result = false; try {
Context context = this.getApplicationContext();
ConnectivityManager connectivityMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityMgr.getActiveNetworkInfo();
if (networkInfo != null) {
result = networkInfo.isAvailable();
}
}
catch (Exception e) {
Log.e("test", "get active network info leave: " + e.getMessage());
} return result;
}

 

简单的网络检查,却在connectivityMgr.getActiveNetworkInfo();时抛出如下异常:

java.lang.SecurityException: ConnectivityService: Neither user 10037 nor current process has android.permission.ACCESS_NETWORK_STATE.

原因:SecurityException,显然是权限不够。

解决方案:在AndroidManifest.xml中,加入如下权限:

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

SecurityException的更多相关文章

  1. 执行打的maven jar包时出现“Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes”

    Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for ...

  2. bug--service--Caused by java.lang.SecurityException: Unable to start service Intent { }:user 0 is restricted

    http://bbs.coloros.com/thread-174655-1-1.html 急!!Service在OPPO系列手机下无法启动,寻求帮助 你好,我是网易邮件事业部1元夺宝开发工程师,最近 ...

  3. Android异常:唤醒锁未授权。(Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK.)

    Android异常:Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android ...

  4. System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

    [15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...

  5. System.Security.SecurityException The source was not found, but some or all event logs could not be searched.Inaccessible logs Security.

    An exception occurred during the Install phase. System.Security.SecurityException The source was not ...

  6. paip.自动import的实现跟java.lang.SecurityException Prohibited package name java

    paip.自动import的实现跟java.lang.SecurityException Prohibited package name java #-----自动import 因为java.lang ...

  7. 使用sqljdbc连接mssql数据库,maven生成jar运行后报"Exception in thread "main" java.lang.SecurityException"错误

    错误信息如下: Exception in thread "main" java.lang.SecurityException: Invalid signature file dig ...

  8. Windows服务安装异常:System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security

    Windows服务安装异常:System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志.不可 访问的日志: Security 2种方法处理: 一.右键 ...

  9. 解决dwr报错【 Error: java.lang.SecurityException: No class by name: service】

    打开包含dwr的网页时后台报错: 警告: Names of known classes are: __System DwrQueryService 十二月 11, 2015 10:24:44 上午 o ...

  10. 某APK中使用了动态注册BroadcastReceiver,Launcher中动态加载此APK出现java.lang.SecurityException异常的解决方法

    在某APK中,通过如下方法动态注册了一个BroadcastReceiver,代码参考如下: @Override protected void onAttachedToWindow() { super. ...

随机推荐

  1. WebRTC 入门到放弃(一)WebRTC

    前言 WebRTC,名称源自网页实时通信(Web Real-Time Communication)的缩写,是一个支持网页浏览器进行实时语音对话或视频对话的技术,是谷歌2010年以6820万美元收购Gl ...

  2. IE下javascript cookie path设置Bug

    项目中设置完cookie,在Firefox下顺利测试通过.IE测试出现问题,经定位发现是Javascript设置 Cookie 时的 path 有问题.IE下Cookie设置在 /或者URL所在路径时 ...

  3. eclipse导入工程时,出现Some projects cannot be imported because they already exist in the workspace

    前提条件: 1.将eclipse中现有的工程javatraining删除,如下图所示, 该复选框不要勾选,点击ok steps: 1.本次打开Eclipse想要把已删除的javatraining工程再 ...

  4. Linux CentOS 6.5 配置网络

    网卡说明 第一块网卡为配置外网:eth0 第二块网卡为配置内网:eth1(没有外网的机器也要将内网配置在第二块网卡上) 1.使用ifconfig查看网卡配置信息 2.修改网卡1配置文件/etc/sys ...

  5. C#学习笔记-建造者模式

    题目:用程序画一个小人. 实现: public partial class Form1 : Form { public Form1() { InitializeComponent(); } priva ...

  6. 接口测试——Java + TestNG 国家气象局接口(json解析)实例

    后端测试,主要以测试接口为主.需要代码支撑,近期便找了个天气接口捣鼓了. 使用到的工具是:Eclipse + TestNG + Maven + ReportNG,全国城市编码:http://www.c ...

  7. burpsuite截断绕过前端限制上传一句话

    设置代理,这里就不说了 打开上传界面 burpsuite开启拦截,上传lurp.hpg 在burp找到上传文件的格式改回原来一句话的格式 上传= =

  8. cs231n spring 2017 lecture15 Efficient Methods and Hardware for Deep Learning 听课笔记

    1. 深度学习面临的问题: 1)模型越来越大,很难在移动端部署,也很难网络更新. 2)训练时间越来越长,限制了研究人员的产量. 3)耗能太多,硬件成本昂贵. 解决的方法:联合设计算法和硬件. 计算硬件 ...

  9. deeplearning.ai 构建机器学习项目 Week 2 机器学习策略 II 听课笔记

    1. 误差分析(Error analysis) 误差分析的目的是找到不同误差源的比重,从而指引我们接下来往哪个方向努力改进.NG建议手工统计随机100个错误的误差源,比如对于猫分类器,错误的照片可能是 ...

  10. Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)

    A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...