has Mobile Connection - Android Network

Android examples for Network:Network Connection

Description

has Mobile Connection

Demo Code


//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static Boolean hasMobileConnection(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo mobileNetwork = cm//from   w ww. j  a  v  a 2 s . c  om
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileNetwork != null && mobileNetwork.isConnected()) {
            return true;
        }

        return false;
    }
}

Related Tutorials