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"/>
时间: 2024-11-08 22:22:17

Android SecurityException的相关文章

Android 开发之错误整理java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10088 nor current process has android.permission.READ_PHONE_STATE.

java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10088 nor current process has android.permission.READ_PHONE_STATE. 今天写了一款发短信的软件,拿了个酷派5879,试了下,结果不能用,把try{}catch{}去掉了,报这个错误, android.permission.READ_PHONE_STATE.没有READ_PHONE_STATE权限,

AIDL 发生异常的原因 Android java.lang.SecurityException: Binder invocation to an incorrect interface

我建立了两个project.一个是activity 的 ,一个是service 的. 在进行两个project通信时,应该有以下几点注意: 1.在activity project中引入service project中aidl文件.注意引入后的aidl文件包名应该和service中aidl文件包名保持一致. 2.service project中manifest文件中,service 注册时要声明 android:process=":remote" action应该是aidl中接口的包名.

【Android】java.lang.SecurityException: Permission Denial: starting Intent 应用启动失败异常

异常提示 在Eclipse和Android Studio同时使用的时候,我遇到过这样一个异常,具体错误提示如下: ava.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.xxx.xxx/.activity.SplashActivity }

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://...

在as中创建cordova中添加从相册选取照片的插件 $cordovaImagePicker 就是以上这货,调用后直接程序就崩溃了,并报错 Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://... 添加权限 <uses-permission android:name="android.permis

Android 4.4: java.lang.SecurityException: Package com.android.settings does not belong to 1001

问题描述: 在Android4.4.2上面定制的东西,今天code base改为Android4.4.4. 代码merge到新的Android 4.4.4 code base后,clean build后会报出下面错误: 1 W/dalvikvm( 3125): threadid=1: thread exiting with uncaught exception (group=0x415e8d58) 2 W/AppOps ( 1053): Bad call: specified package c

Android将Google Play Store放到可卸载区,登录时报SecurityException错误

客户需求要求Google Play Store(Phonesky.apk)为可卸载,需要放到system/vendor/operator/app下面.这样在登录Play Store时会遇到以下错误,无法使用: FATAL EXCEPTION :download-manager-thread Process: com.android.vending, PID:3016 java.lang.SecurityException:Invalid value for is_public_api: null

Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG

crash information:Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG from    at android.os.Parcel.readException(Parcel.java:1465)     at android.os.Parcel.readException(Parcel.j

Android应用流量统计——NetworkStatsManager使用

在没有Root的情况下,Android应用流量统计在6.0之前一直没有太好的办法,官方虽然提供了TrafficStats,但其主要功能是设备启动以来流量的统计信息,和时间信息无法很好的配合.最近再看TrafficStats类时,发现说明中提到,为获取更具鲁棒性的网络历史数据,建议使用NetworkStatsManager. 本文首先简单对比下TrafficStats和NetworkStatsManager各自的限制和优缺点,然后详细说明NetworkStatsManager的用法,并给出主要代码

android Broadcast 总结

1, 生命周期 在android官方文档中,推荐我们在onResume中进行 registerReceiver, 在onPause中进行unRegisterReceiver. 他们给出的理由是: If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won't receive intents when pa