Android 判断是否打开移动网络开关

来源:互联网 发布:小c语言程序 编辑:程序博客网 时间:2024/04/29 08:08

Android 判断是否打开移动网络开关

public static boolean isMobileEnabled(Context context) {    try {        Method getMobileDataEnabledMethod = ConnectivityManager.class.getDeclaredMethod("getMobileDataEnabled");        getMobileDataEnabledMethod.setAccessible(true);        return (Boolean) getMobileDataEnabledMethod.invoke(getConnectivityManager(context));    } catch (Exception e) {        e.printStackTrace();    }    // 反射失败,默认开启    return true;}
0 1