rayman
rayman

Reputation: 21596

Determine connection state

I am trying to determine if my current connection state is WIFI or Cell network (3g/2g... etc) I am using SDK 1.5.

Tried couple of technics not realy working.

Any working suggestions?

Thanks,

ray.

Upvotes: 2

Views: 738

Answers (2)

pengwang
pengwang

Reputation: 19946

i forget the sdk version ,if you look for"WIFI" or "MOBILE", you may ues ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

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

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

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

Upvotes: 1

Pentium10
Pentium10

Reputation: 207830

I think NetworkInfo has a field for this.

Check out getTypeName() Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE", go check out here

Upvotes: 1

Related Questions