开发者

Determine connection state

开发者 https://www.devze.com 2023-01-01 09:17 出处:网络
I am tryingto determine if my current connection state is WIFI or Cell network (3g/2g... etc) I am using SDK 1.5.

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 r开发者_如何学编程ealy working.

Any working suggestions?

Thanks,

ray.


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


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 }

0

精彩评论

暂无评论...
验证码 换一张
取 消