Is Network APN Connection - Android Network

Android examples for Network:Network Connection

Description

Is Network APN Connection

Demo Code


//package com.java2s;

import android.content.Context;

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

public class Main {

    public static boolean checkNetWork(Context context) {

        boolean isWIFI = isWIFIConnection(context);
        boolean isAPN = isAPNConnection(context);

        if (!isWIFI && !isAPN) {
            return false;
        }//ww w  . j  a  va2  s . c o  m


        return true;
    }

    private static boolean isWIFIConnection(Context context) {

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

        NetworkInfo networkInfo = manager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (networkInfo != null) {
            return networkInfo.isConnected();
        }
        return false;
    }

    private static boolean isAPNConnection(Context context) {

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

        NetworkInfo networkInfo = manager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (networkInfo != null) {
            return networkInfo.isConnected();
        }
        return false;
    }
}

Related Tutorials