Is Network Connection LTE - Android Network

Android examples for Network:Network Connection

Description

Is Network Connection LTE

Demo Code


//package com.java2s;
import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import android.os.Build;
import android.telephony.TelephonyManager;

public class Main {

    public static final int NETWORK_TYPE_NO_CONNECTION = -1231545315;

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static boolean isLTEBySubtype(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            return false;
        } else {/* www .j  a v  a2s.c o  m*/
            return getCurrentNetworkSubtype(context) == TelephonyManager.NETWORK_TYPE_LTE;
        }
    }

    public static int getCurrentNetworkSubtype(Context context) {
        NetworkInfo networkInfo = ((ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        return networkInfo != null ? networkInfo.getSubtype()
                : NETWORK_TYPE_NO_CONNECTION;
    }
}

Related Tutorials