Returns the active network info. - Android Network

Android examples for Network:Network Status

Description

Returns the active network info.

Demo Code


//package com.java2s;
import android.content.Context;

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

public class Main {
    /**/*  w  w w  . j  a  v a 2s . c o m*/
     * Returns the active network info.
     *
     * @param context
     * @return
     */
    public static String getNetworkType(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
        return (null != activeNetworkInfo) ? activeNetworkInfo
                .getTypeName() : null;
    }
}

Related Tutorials