get NetWork Name - Android Network

Android examples for Network:Network Status

Description

get NetWork Name

Demo Code


//package com.java2s;

import android.content.Context;

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

public class Main {
    public static String getNetWorkName(Context context) {
        return getNetworkType(context).toLowerCase();
    }/*from   w w w.  j a va 2  s. c  om*/

    public static String getNetworkType(Context context) {
        NetworkInfo networkInfo = ((ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        if ((networkInfo != null) && (networkInfo.isAvailable())) {
            if (networkInfo.getTypeName().toLowerCase().equals("wifi"))
                return "wifi";
            return networkInfo.getExtraInfo().toLowerCase();
        }
        return "wifi not available";
    }
}

Related Tutorials