我想知道是否可以从Windows Phone应用程序检索网络使用情况。我知道在Android和iOS中这是可能的。
对于WP,搜索我发现此课程的文档:Windows.Networking.Connectivity
(http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.connectivity.aspx)
从那里我看到了可以检索的NetworkUsage
类:
BytesReceived
:只读 - 表示连接在特定时间段内收到的字节数。BytesSent
:只读 - 表示连接在特定时间段内发送的字节数。ConnectionDuration
:只读 - 表示连接的持续时间。但由于我不是WP开发人员,我无法理解这是否是公共API ...是否有任何建议?
答案 0 :(得分:2)
公开:http://msdn.microsoft.com/en-US/library/windows/apps/hh465162.aspx
这是一个有效的C#示例:
//Set end Time to now
var currTime = DateTime.Now;
//Set start Time to 1 hour before current time
var startTime = currTime - TimeSpan.FromHours(1);
//Get the ConnectionProfile that is currently used to connect to the Internet
var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
var localUsage = await connectionProfile.GetNetworkUsageAsync(startTime, currTime, DataUsageGranularity.Total, new NetworkUsageStates());
foreach (var usage in localUsage)
{
Debug.WriteLine("Local Data Usage: \n\r"
+ "Bytes Sent: " + usage.BytesSent + "\n\r"
+ "Bytes Received: " + usage.BytesReceived + "\n\r");
}
给我:
Local Data Usage:
Bytes Sent: 757658
Bytes Received: 917693