Code example for ConnectivityManager

Methods: getMobileDataEnabled, sleep

0
    private static boolean getDataState(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        try { 
            /* Make sure the state change propagates */ 
            Thread.sleep(100);
        } catch (java.lang.InterruptedException ie) {
        } 
        return cm.getMobileDataEnabled();
    } 
 
    /** 
     * Toggles the state of data. 
     */ 
    public void toggleState(Context context) {
        boolean enabled = getDataState(context);
 
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
 
        if (enabled) {