10

I want to check if a particular device has hardware support for 4G networks.

I will elaborate the issue...
In the application we have a settings page where user can make selection and allow application to run only in selected networks. Eg. User can select that app will run only in WiFi network or only in 3G network etc.

There are CheckBox preferences for all networks WiFi, 2G, 3G 4G etc. Now if the device doesn't have the support for 4G network, I want to hide the 4G selection checkbox.
All the remaining functionality is complete. I am struck on just this issue that how to detect if device support 4G or not?
Please note that I want to detect hardware support for 4G on the device and NOT the 4G connection is connected or so.
Any help is greatly appreciated.

manlio
  • 16,658
  • 13
  • 67
  • 107
Udayan
  • 1,314
  • 1
  • 10
  • 19

3 Answers3

3
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.

Josh
  • 9,960
  • 2
  • 30
  • 36
user550925
  • 96
  • 2
  • 1
    Doesn't work, this also gives you the currently active network types, and not the hardware capabilities. Changing preferred network type in Settings to 2G or 3G gives different results. – ballzak Apr 12 '15 at 02:05
  • From google's documentation the getAllNetworkInfo method of the connectivity manager becomes deprecated in API level 23, and it is recommended to use getAllNetworks and getNetworkInfo subsequently. Yet again, getAllNetworks is available only for API level 21+ – Akah Dec 24 '15 at 11:14
  • @ballzak did you get any solution ? – Narayan soni Feb 06 '18 at 06:04
1

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.

Nick
  • 8,824
  • 32
  • 98
  • 143
  • Hi Nick, Thanks for the reply. But I don't think this solves my problem. I want to detect whether there is a hardware for 4G present in the device. i.e. Does the device have 4G capability? I don't want to know if 4G connection is connected or not. This part I have already done. – Udayan Oct 31 '11 at 10:15
0
  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.

lutakyn
  • 324
  • 4
  • 17
Richa
  • 3,148
  • 1
  • 19
  • 25