tags:

views:

137

answers:

2
+1  Q: 

Get Network type

hello,

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

any other suggestions will be welcome,

thanks!

+2  A: 

To get the network type (I think your talking about wifi or mobile) you can use this code snippet:

ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

//mobile
State mobile = conMan.getNetworkInfo(0).getState();

//wifi
State wifi = conMan.getNetworkInfo(1).getState();

and then use it like that:

if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
    //mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
    //wifi
}

To get the type of the mobile network I would try TelephonyManager#getNetworkType or NetworkInfo#getSubtypeName

Roflcoptr
Yes this is checking weather i`am on wifi or not.. and it does work!but is there also a way of checking my network type?(for example i am onto IDEN/GSM..)?
Moshik
i editet my ansewr
Roflcoptr
It didnt work after i tried it with Wifi... it's still eneter into the first condisiton.. seems like NetworkInfo.State.CONNECTED always return true.. any idea?
Moshik
+1  A: 

Hi check this link

Praveenb