此处的打开,不是指连接与否,而是相对于打开关闭说的
/**
* 获取数据开关状态 5.0以上系统使用
*
* @return
*/
public boolean getMobileDataState() {
try {
TelephonyManager telephonyService = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Method getDataEnabled = telephonyService.getClass().getDeclaredMethod("getDataEnabled");
if (null != getDataEnabled) {
return (Boolean) getDataEnabled.invoke(telephonyService);
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
网友评论