I plan to load only as much data as required in my app. Which means, that when the data is loaded via Wifi, I want to prefetch things. If the data is loaded via mobile plan
Let's solve it by myself:
There is the Data Sense API, which allows one to not only check whether the device is roaming, but also check whether the app approaches or is over the data limit set in Data Sense. The API also works when the provider doesn't allow to usse the Data Sense UI.
In particular, this code from the link above solves everything!
// Get current Internet Connection Profile.
ConnectionProfile internetConnectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
// Check the connection details.
if (internetConnectionProfile.NetworkAdapter.IanaInterfaceType != IANA_INTERFACE_TYPE_WIFI)
{
// Connection is not a Wi-Fi connection.
if (internetConnectionProfile.GetConnectionCost().Roaming)
{
// User is roaming. Don't send data out.
m_bDoNotSendData = true;
}
if (internetConnectionProfile.GetConnectionCost().ApproachingDataLimit)
{
// User is approaching data limit. Send low-resolution images.
m_bSendLowResolutionImage = true;
}
if (internetConnectionProfile.GetConnectionCost().OverDataLimit)
{
// User is over data limit. Don't send data out.
m_bDoNotSendData = true;
}
}
else
{
//Connection is a Wi-Fi connection. Data restrictions are not necessary.
m_bDoNotSendData = false;
m_bSendLowResolutionImage = false;
}
// Optionally, report the current values in a TextBox control.
string cost = string.Empty;
switch (internetConnectionProfile.GetConnectionCost().NetworkCostType)
{
case NetworkCostType.Unrestricted:
cost += "Cost: Unrestricted";
break;
case NetworkCostType.Fixed:
cost += "Cost: Fixed";
break;
case NetworkCostType.Variable:
cost += "Cost: Variable";
break;
case NetworkCostType.Unknown:
cost += "Cost: Unknown";
break;
default:
cost += "Cost: Error";
break;
}
cost += "\n";
cost += "Roaming: " + internetConnectionProfile.GetConnectionCost().Roaming + "\n";
cost += "Over Data Limit: " + internetConnectionProfile.GetConnectionCost().OverDataLimit + "\n";
cost += "Approaching Data Limit : " + internetConnectionProfile.GetConnectionCost().ApproachingDataLimit + "\n";
NetworkStatus.Text = cost;