Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Network type

Tags:

android

I've been trying to retrive the current network type, but no success

when i say network type: i refer to know this info: if the type is: NETWORK_TYPE_IDEN or NETWORK_TYPE_UMTS.. and so on..

i tried to use:

NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();

or

NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo 
            (ConnectivityManager.TYPE_MOBILE); 

but no success..

i am doing this coz i wanna know if the current network is IDEN, or if the current network is connected through wifi..

like image 518
Moshik Avatar asked May 27 '10 08:05

Moshik


2 Answers

In Android API LEVEL 30 getNetworkType has deprecated. Use getDataNetworkType() , and provide android.permission.READ_PHONE_STATE

like image 147
Wladimir Koroy Avatar answered Oct 20 '22 09:10

Wladimir Koroy


I am using this function:

public String get_network()
       {Activity act=(Activity)context;
        String network_type="UNKNOWN";//maybe usb reverse tethering
        NetworkInfo active_network=((ConnectivityManager)act.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (active_network!=null && active_network.isConnectedOrConnecting())
           {if (active_network.getType()==ConnectivityManager.TYPE_WIFI)
               {network_type="WIFI";
               }
            else if (active_network.getType()==ConnectivityManager.TYPE_MOBILE)
                 {network_type=((ConnectivityManager)act.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo().getSubtypeName();
                 }
           }
        return network_type;
       }
like image 31
diyism Avatar answered Oct 20 '22 09:10

diyism