How to access a specific type of Windows Phone 7 network (e.g. EDGE, 3G, etc.) without opening a socket?

As I understand it, before upgrading the Mango SDK (7.1), you could access a fairly wide network type using the NetworkInterface.NetworkInterfaceType property. This will return an enumeration such as Wireless80211 , MobileBroadbandGSM or MobileBroadbandCDMA .

After the release of the Mango SDK, we can now access NetworkInterfaceSubtype through an open socket using a call like this: socket.GetCurrentNetworkInterface(); The return object property ( NetworkInterfaceInfo.InterfaceSubtype ) will give you more specific network information such as Cellular_EDGE , Cellular_HSPA or Cellular_EVDV . This is the information I need.

The most efficient way I found access was to open an asynchronous host name resolution request and capture the information in the async callback function, for example below (borrowed from this message: How can I check 3G, Wi-Fi, EDGE, cellular networks in Windows Phone 7?:

 DeviceNetworkInformation.ResolveHostNameAsync( new DnsEndPoint("microsoft.com", 80), new NameResolutionCallback(nrr => { var info = nrr.NetworkInterface; var subType = info.InterfaceSubtype; }), null); 

What I'm looking for is a way to access this NetworkSubtype information without actually opening a data connection. The reason I need a passive method for requesting this information is because I need to know when the type of network changes, but constantly opening a data connection in a loop that requests it can potentially prevent this change.

UPDATE 1: I found through testing that, as Richard Salay suggested, the DeviceNetworkInformation.NetworkAvailabilityChanged event really fires when the phone switches network technologies (e.g. 3G to EDGE or WiFi to HSPA) and you have access to NetworkInterfaceSubtype . Unfortunately, I also found that when switching from Wi-Fi to cellular network technology (for example, HSPA, EDGE), the specified network subtype can often be inaccurate. For example, if you switch from Wi-Fi to HSPA, the event arguments may indicate a Wi-Fi connection when it starts, and no second event will be sent for the HSPA message. Thus, you get the wrong type of connection. This insecurity may make using this trigger ultimately useless, but I'm going to do some network testing (without WiFi) to see if this problem is limited to switching WiFi. I hope this is just a problem with the Wi-Fi radio and this message about the cellular network is being reported accurately. I will update this when I learn more.

UPDATE 2: I found that during testing (driving), when the DeviceNetworkInformation.NetworkAvailabilityChanged event leads to network changes, it is not possible to pinpoint what triggers / triggers the event. For example, if you record a network interface every time an event is triggered, you can get results such as: HSPA, EDGE, EDGE, EDGE, GPRS, GPRS, HSPA. The event argument object has a variable called NotificationType that should tell you the reason it was run, but in my tests it always sets CharacteristicUpdate , so I have no idea why it runs several times for the same type of network (e.g. EDGE , EDGE, EDGE). For my purposes, I simply record changes that have not yet been recorded, and ignoring the multiplicity. It's not perfect (and seems a little less reliable), but it's better than nothing, I suppose.

+4
source share
2 answers

I sent the answer to which you took the code, and I worked a little on this question (including through the reflected source of the WP7 structure).

Unfortunately, NetworkSubType not published publicly from any place that is not the result of an open connection, and resolving the host name is the easiest.

The only thing I can recommend is to run a test to determine if DeviceNetworkInformation.NetworkAvailabilityChanged will work when the data type changes (say, from 3G to H). If this is the case, you can perform a different resolution at that time (although even this may prove to be too expensive). If not, I'm afraid you're out of luck.

+3
source

Register with DeviceNetworkInformation.NetworkAvailabilityChanged , then get the NetworkInterfaceSubtype list as follows:

 var currentList = new NetworkInterfaceList().Where(i => i.InterfaceState == ConnectState.Connected).Select(i => i.InterfaceSubtype); if (currentList.Contains(NetworkInterfaceSubtype.WiFi)) Debug.WriteLine("WiFi"); if (currentList.Intersect(new NetworkInterfaceSubType[] { NetworkInterfaceSubtype.Cellular_EVDO, NetworkInterfaceSubtype.Cellular_3G, NetworkInterfaceSubtype.Cellular_HSPA, NetworkInterfaceSubtype.Cellular_EVDV, }).Any()) Debug.WriteLine("3G"); if (currentList.Intersect(new NetworkInterfaceSubType[] { NetworkInterfaceSubtype.Cellular_GPRS, NetworkInterfaceSubtype.Cellular_1XRTT, NetworkInterfaceSubtype.Cellular_EDGE, }).Any()) Debug.WriteLine("2G"); 
0
source

Source: https://habr.com/ru/post/1389166/


All Articles