首页 > 代码库 > Android SecurityException
Android SecurityException
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"/>
Android SecurityException
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。