use of android.net.ConnectivityManager in project android-app by eoecn.
the class NetWorkHelper method isMobileDataEnable.
/**
* 判断MOBILE网络是否可用
*
* @param context
* @return
* @throws Exception
*/
public static boolean isMobileDataEnable(Context context) throws Exception {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isMobileDataEnable = false;
isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
return isMobileDataEnable;
}
use of android.net.ConnectivityManager in project android-job by evernote.
the class Device method getNetworkType.
@NonNull
public static JobRequest.NetworkType getNetworkType(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
return JobRequest.NetworkType.ANY;
}
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null && telephonyManager.isNetworkRoaming()) {
return JobRequest.NetworkType.CONNECTED;
}
boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
return metered ? JobRequest.NetworkType.NOT_ROAMING : JobRequest.NetworkType.UNMETERED;
}
use of android.net.ConnectivityManager in project android_frameworks_base by ParanoidAndroid.
the class MobileDataButton method toggleState.
@Override
protected void toggleState(Context context) {
boolean enabled = getDataState(context);
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (enabled) {
cm.setMobileDataEnabled(false);
} else {
cm.setMobileDataEnabled(true);
}
}
use of android.net.ConnectivityManager in project android_frameworks_base by ParanoidAndroid.
the class WifiWatchdogStateMachine method makeWifiWatchdogStateMachine.
public static WifiWatchdogStateMachine makeWifiWatchdogStateMachine(Context context) {
ContentResolver contentResolver = context.getContentResolver();
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
sWifiOnly = (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false);
// Watchdog is always enabled. Poor network detection can be seperately turned on/off
// TODO: Remove this setting & clean up state machine since we always have
// watchdog in an enabled state
putSettingsGlobalBoolean(contentResolver, Settings.Global.WIFI_WATCHDOG_ON, true);
WifiWatchdogStateMachine wwsm = new WifiWatchdogStateMachine(context);
wwsm.start();
return wwsm;
}
use of android.net.ConnectivityManager in project robotium by RobotiumTech.
the class SystemUtils method setMobileData.
/**
* Sets if mobile data should be turned on or off. Requires android.permission.CHANGE_NETWORK_STATE in the AndroidManifest.xml of the application under test.
*
* @param turnedOn true if mobile data is to be turned on and false if not
*/
public void setMobileData(Boolean turnedOn) {
ConnectivityManager dataManager = (ConnectivityManager) instrumentation.getTargetContext().getSystemService(Context.CONNECTIVITY_SERVICE);
Method dataClass = null;
try {
dataClass = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataClass.setAccessible(true);
dataClass.invoke(dataManager, turnedOn);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations