check this device has mobile module or not - Android Network

Android examples for Network:Network Connection

Description

check this device has mobile module or not

Demo Code


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

public class Main {
    private static boolean sIsInit = false;
    private static boolean sHasMobile = false;

    /**/* w  ww . ja v a  2s .co  m*/
     * check this device has mobile module or not
     * @return true if has mobile module
     */
    public static boolean hasMobile(Context context) {
        init(context);
        return sHasMobile;
    }

    private static synchronized void init(Context context) {
        if (!sIsInit) {
            ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(Activity.CONNECTIVITY_SERVICE);
            if (cm == null) {
                return;
            }
            NetworkInfo[] allNetworkInfo = cm.getAllNetworkInfo();
            if (allNetworkInfo == null) {
                return;
            }
            sIsInit = true;
            for (NetworkInfo ni : allNetworkInfo) {
                int type = ni.getType();
                if (type == ConnectivityManager.TYPE_MOBILE
                        || type == ConnectivityManager.TYPE_MOBILE_DUN
                        || type == ConnectivityManager.TYPE_MOBILE_HIPRI
                        || type == ConnectivityManager.TYPE_MOBILE_MMS
                        || type == ConnectivityManager.TYPE_MOBILE_SUPL) {
                    sHasMobile = true;
                    break;
                }
            }
        }
    }
}

Related Tutorials