15

Is there a way to debug airplane mode on the device? I tried turning airplane mode on in the device settings and disabling the internet connection on my computer, but NetworkInterface.GetIsNetworkAvailable() still returns true. Am I doing something wrong?

Jacob
  • 77,566
  • 24
  • 149
  • 228
CACuzcatlan
  • 5,407
  • 8
  • 41
  • 59

3 Answers3

7

Notice the comment on the bottom of the official doc:

This API will always return true on the Windows Phone 7 emulator. Testing therefore requires a facade, mock or conditional chunk of code.

I just tested this on an actual device and indeed, it returns a constant true.

However, the thing is - it is all because you keep your phone connected to the PC and the Ethernet interface is available. Once you disconnect the phone and start the app, you will see that a False will be returned.

Mick N
  • 14,892
  • 2
  • 35
  • 41
Den
  • 16,686
  • 4
  • 47
  • 87
  • Although it also returns true on device (not emulator) when debugging. – CACuzcatlan Feb 03 '11 at 03:26
  • Notice my edit - disconnect the phone from the PC to test the capability. – Den Feb 03 '11 at 03:26
  • 1
    For an example of such a interface, check out the NetworkStatusProvider from the WP7 United Nations News app @ http://unitednations.codeplex.com/SourceControl/changeset/view/70986#1461137 – JustinAngel Feb 03 '11 at 03:49
  • Dennis, I know I can test it when disconnected, but I'd like to be able to debug as well. – CACuzcatlan Feb 03 '11 at 19:20
  • There are some conditions that you can't avoid, and this is one of them. You can debug it manually by using a simple logging mechanism or simply display message boxes with exception data, if any. – Den Feb 03 '11 at 21:53
2

It's possible that WiFi and/or Bluetooth weren't disabled. This might cause GetIsNetworkAvailable() to return true. According to this page:

While you're in Airplane mode, you can still turn your phone's Wi-Fi and Bluetooth on and off separately.

Maybe the assumption the device is making is that you probably only want to turn of Cellular access automatically, and Bluetooth/WiFi separately.

Chris Laplante
  • 29,338
  • 17
  • 103
  • 134
  • Airplane mode is on, wi-fi and bluetooth are turned off, the computer's internet (wi-fi and ethernet) are disabled, but GetIsNetworkAvailable() still returns true. – CACuzcatlan Feb 03 '11 at 02:20
  • because probably GetIsNetworkAvailable() does not check if you have the internet, it just checks if phone is connected. – Lukasz Madon Feb 03 '11 at 02:31
  • Connected to what? According to MSDN the method returns "true if a network connection is available; otherwise, false." If there is no internet connection, it should return false, and it works as expected when the I'm not debugging on device. – CACuzcatlan Feb 03 '11 at 03:01
  • "How to debug airplane mode on device" "I'm not debugging on device" this is a bit contrary, isn't it? :P – Lukasz Madon Feb 03 '11 at 03:30
  • Not debugging on the device means testing the application in the emulator, which is quite precise when it comes to network connection availability. Therefore the statement was - "works on the emulator but not on the device" – Den Feb 03 '11 at 03:40
1

You can check what kind of interface is available: NetworkInterfaceType

NetworkInterfaceType.MobileBroadbandCdma:
NetworkInterfaceType.MobileBroadbandGsm

These should be disabled.

Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108