get Network Is Wifi Or 3G - Android Network

Android examples for Network:Network Operation

Description

get Network Is Wifi Or 3G

Demo Code


//package com.java2s;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static String getNetIsWifiOr3G(Context context) {

        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetInfo = connectivityManager
                .getActiveNetworkInfo();
        if (activeNetInfo == null)
            return "none";
        else if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI)
            return "WIFI";
        else if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE)
            return "2G3G";
        else//ww  w .  ja  v  a  2s  .c o  m
            return "unknown";
    }
}

Related Tutorials