get Active Network Info - Android Network

Android examples for Network:Network Operation

Description

get Active Network Info

Demo Code


//package com.java2s;

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

public class Main {
    public static NetworkInfo getActiveNetworkInfo(Context context) {
        // func: context.getSystemService(String name)
        // constant value: "connectivity" --> CONNECTIVITY_SERVICE retrieve a
        // connectivityManager for handling
        // management of network connections
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService("connectivity");
        return connectivity.getActiveNetworkInfo();
    }/*  w  w w  .  j  av a  2  s  .  c  o  m*/
}

Related Tutorials