Android SecurityException
Posted 星辰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
Android:java.lang.SecurityException:权限拒绝:启动意图
Android SecurityException: getDataNetworkTypeForSubscriber问题修复
SecurityException - “调用者......不是范围委托阻止卸载的代表”(Android 8 - Java)
Android 9.0 NotificationManager.notify() 抛出 java.lang.SecurityException
SecurityException:权限拒绝:读取 com.android.providers.media.MediaProvider 需要 android.permission.READ_EXTER