Search code examples
c#silverlightwindows-phone-8windows-phonewindows-phone-8-emulator

DeviceNetworkInformation.IsCellularDataEnabled always returns false


I recently installed the Windows Phone 8.1 emulators to try some existing apps out on them and ran into this problem: DeviceNetworkInformation.IsCellularDataEnabled (in the Microsoft.Phone.Net.NetworkInformation namespace) is always returning false.

public void UpdateDataEnabled()
{
    _dataEnabled = DeviceNetworkInformation.IsCellularDataEnabled 
        || DeviceNetworkInformation.IsWiFiEnabled;
}

DeviceNetworkInformation.IsCellularDataEnabled = false

I know the connection is actually working because I'm still able to perform HTTP requests. If I run this same exact code in the 8.0.x emulators I don't have any problems.

I also tried updating the project and all libraries to Windows Phone Silverlight 8.1 apps to see if that would resolve the issue and no luck. I checked all the capabilities and ID_CAP_NETWORKING was still checked as well.

The emulator is tested and working if I write a pure Windows Phone 8.1 XAML app using Windows 8 method of obtaining network status. It's just not working for my Silverlight apps.

I was under the impression that Windows Phone Silverlight apps should continue to function on Windows Phone 8.1 devices. Am I overlooking something?


Solution

  • I have the same problem and i did what verdesrobert and Rishabh876 suggested. Its only emulator problem so i add condition to check out if app is running on emulator

        public bool IsNetworkAvailable()
        {
            if (DeviceNetworkInformation.IsNetworkAvailable)
            {
                if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
                {
                    return true;
                }
                else if ((DeviceNetworkInformation.IsWiFiEnabled || DeviceNetworkInformation.IsCellularDataEnabled) && NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None)
                {
                    return true;
                }
            }
            return false;
        }
    

    I dont like that workaround much so if anyone has better solution let me know.