关于移动数据的的关闭开启,android5.0之前的方式是
/**
* 启动、禁用移动数据
* @param context
* @param flag
* @param chkCurrent 是否需检查当前状态
*/
public static void allowMobileData(Context context, boolean flag, boolean... chkCurrent) throws Exception {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
……
Method enabledMethod = cm.getClass().getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
enabledMethod.setAccessible(true);
enabledMethod.invoke(cm, flag);
}
但是在5.0以及以上的系统,这个调用方式已经失效。
API说明如下:
Deprecated:
Talk to TelephonyManager directly
Hide:
1291
1292 public boolean More ...getMobileDataEnabled() {
1293 IBinder b = ServiceManager.getService(Co