How to check whether a particular device supports 4G networks in Android?

▼魔方 西西 提交于 2019-12-03 01:05:37
user550925
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo[] info = cm.getAllNetworkInfo();
   for(int i=0; i <info.length; i++){
       Log.i("netinfo"+i, info[i].getType()+"");
       Log.i("netinfo"+i, info[i].getTypeName());
       Log.i("netinfo"+i, info[i].getSubtype()+"");
       Log.i("netinfo"+i, info[i].getSubtypeName());
   }

Use this piece of code and get all available options on the device. I think you should be able to get all capabilities of the device.

and network type info is present in http://developer.android.com/reference/android/telephony/TelephonyManager.html.

I think network types added from API level 11 are for 4g. Check it yourself.

This might work. It should check for WiMax 4g:

    private boolean is4gavailable() {
    ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mobileInfo = connec.getNetworkInfo(0);
    NetworkInfo wifiInfo = connec.getNetworkInfo(1);
    NetworkInfo wimaxInfo = connec.getNetworkInfo(6);


    if (wimaxInfo!=null) {
    return mobileInfo.isConnectedOrConnecting() || wifiInfo.isConnectedOrConnecting() || wimaxInfo.isConnectedOrConnecting();
    }
    else {
    return mobileInfo.isConnectedOrConnecting() || wifiInfo.isConnectedOrConnecting();
    }
}

Try looking at this for a little more clarification.

Richa
  Context context = MainActivity.this;
  public synchronized static boolean isNetAvailable(Context context){

        boolean isNetAvailable=false;

        if ( context != null ){
            ConnectivityManager mgr = (ConnectivityManager) 
  context.getSystemService(Context.CONNECTIVITY_SERVICE);
            if ( mgr != null )
               {
                boolean mobileNetwork = false;
                boolean wifiNetwork = false;
                boolean wiMaxNetwork = false;
                boolean mobileNetworkConnecetd = false;
                boolean wifiNetworkConnecetd = false;
                boolean wiMaxNetworkConnected = false;
                NetworkInfo mobileInfo = mgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                NetworkInfo wifiInfo = mgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                NetworkInfo wiMaxInfo = mgr.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
                if ( mobileInfo != null )
                    mobileNetwork = mobileInfo.isAvailable();                       
                if ( wifiInfo != null )
                    wifiNetwork = wifiInfo.isAvailable();

                if(wiMaxInfo != null)
                    wiMaxNetwork = wiMaxInfo.isAvailable();

                if(wifiNetwork == true || mobileNetwork == true || wiMaxNetwork == true){
                    mobileNetworkConnecetd = mobileInfo.isConnectedOrConnecting();
                    wifiNetworkConnecetd = wifiInfo.isConnectedOrConnecting();
                    wiMaxNetworkConnected = wiMaxInfo.isConnectedOrConnecting();
                }
                isNetAvailable = ( mobileNetworkConnecetd || wifiNetworkConnecetd || wiMaxNetworkConnected );
            }
        }
        return isNetAvailable;
    }

Check for value of isNetAvailable is true in all the 3 cases this works for me, wish work for u too

Note : 4G availability will be introduces API level 8 onwards.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!