get the current network type - Android Phone

Android examples for Phone:Network

Description

get the current network type

Demo Code


//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**//from w ww  .ja v  a2 s .c  om
     * get the current network type
     * @param context
     * @return
     */
    public static String NetType(Context context) {
        try {
            ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo info = cm.getActiveNetworkInfo();
            if (null == info)
                return null;
            String typeName = info.getTypeName().toLowerCase();
            if (typeName.equals("wifi")) {

            } else {
                typeName = info.getExtraInfo().toLowerCase();
            }
            return typeName;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials