views:

243

answers:

1

Hi,

I want to download some data if user is currently on a wifi connection but if user is connected using cellular data (e.g. 3G) I dont want to do anything to prevent data charges for the user.

In order to do this, I need to know current connection type. Is there any API that would give me this information? (This is a native application.)

Thanks.

+1  A: 

Perhaps you will find this article and sample-code useful.

Another option to verify WLAN-status would be by reading the following registry-value:

HKEY_LOCAL_MACHINE\System\State\Hardware\Wifi

at least according to this post (which I guess you can easily adapt to native code). If WLAN is on, I guess you can safely let the user download data.

Edit: the values obtained seem to correspond to the following WLAN-status:

0 - powered off

1 or 5 - ready

11 or 15 - connecting

19 or 23 - connected

I am not 100% sure if when WLAN is connected, any other data-services such as 3G will not be used. Maybe this depends on the connection-settings. However, when I am using my device, I noted that if WLAN is connected, it "takes command". If you have the possibility, you should verify this using different devices, perhaps with different operators.

Good luck.

moster67
Thanks for the answer. This explains how to get the state of the wifi. But if wifi is enabled does it mean that it it connected and phone is not using data connection?
Szere Dyeri
Please see my edit
moster67
Thanks for the update. It seems to work for me. Although it is not documented is State API (http://msdn.microsoft.com/en-us/library/bb154506.aspx).
Szere Dyeri