UserActivityChannel.GetSessionHistoryItemsForUserActivityAsync 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用户活动的会话历史记录。
public:
virtual IAsyncOperation<IVector<UserActivitySessionHistoryItem ^> ^> ^ GetSessionHistoryItemsForUserActivityAsync(Platform::String ^ activityId, DateTime startTime) = GetSessionHistoryItemsForUserActivityAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IVector<UserActivitySessionHistoryItem>> GetSessionHistoryItemsForUserActivityAsync(winrt::hstring const& activityId, DateTime const& startTime);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IList<UserActivitySessionHistoryItem>> GetSessionHistoryItemsForUserActivityAsync(string activityId, System.DateTimeOffset startTime);
function getSessionHistoryItemsForUserActivityAsync(activityId, startTime)
Public Function GetSessionHistoryItemsForUserActivityAsync (activityId As String, startTime As DateTimeOffset) As IAsyncOperation(Of IList(Of UserActivitySessionHistoryItem))
参数
- activityId
-
String
Platform::String
winrt::hstring
标识要获取其会话历史记录的用户活动。
- startTime
- DateTime DateTimeOffset
获取 startTime 和现在之间处于活动状态的用户活动会话。
返回
在指定用户活动的指定时间内处于活动状态的用户活动会话对象列表。
- 属性
Windows 要求
设备系列 |
Windows 10, version 1803 (在 10.0.17134.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v6.0 中引入)
|
示例
private async void GetMostRecentActivity()
{
UserActivityChannel channel = UserActivityChannel.GetDefault();
// Gets the 10 most recently engaged UserActivity objects, sorted by engagement EndTime (null EndTimes sort first)
IList<UserActivitySessionHistoryItem> recentActivity = await channel. GetRecentUserActivitiesAsync(maxUniqueActivities: 10);
foreach (var activity in recentActivity)
{
var engagements = await channel.GetSessionHistoryItemsForUserActivityAsync(activity.UserActivity.ActivityId, new DateTimeOffset(DateTime.Now, TimeSpan.FromDays(1)));
long totalEngagementTime = 0;
foreach(var e in engagements)
{
if (e.EndTime != null) // EndTime may be null for active UserActivities
{
totalEngagementTime += e.EndTime.Value.Ticks - e.StartTime.Ticks);
}
// App specific code to display the activity engagement time
}
}
}