Code example for ConnectivityManager

Methods: setMobileDataEnabled

0
    @Override 
    protected void toggleState(Context context) {
        if (getDataState(context)) {
            cm.setMobileDataEnabled(false);
        } else { 
            cm.setMobileDataEnabled(true);
        } 
    } 
 
    @Override 
    protected boolean handleLongClick(Context context) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(
           "com.android.settings", 
           "com.android.settings.Settings$DataUsageSummaryActivity")); 
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
        return true; 
    } 
 
    @Override