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 }
精彩评论