Android SecurityException

别裁伪体亲风雅,转益多师是汝师。这篇文章主要讲述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; }

Android SecurityException

文章图片
 
  简单的网络检查,却在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】 

    推荐阅读