Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static final int NO_CONNECTIVITY = 10000;

    static public boolean isMobileConnectivity(Context context) {
        int netType = getNetType(context);
        return (netType == ConnectivityManager.TYPE_MOBILE);
    }

    static private int getNetType(Context context) {
        ConnectivityManager mConnectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = mConnectivity.getActiveNetworkInfo();
        if (info == null) {
            //no connection at all
            return NO_CONNECTIVITY;
        }
        return info.getType();

    }
}