共用方式為


UserActivityChannel.GetSessionHistoryItemsForUserActivityAsync 方法

定義

取得使用者活動的會話歷程記錄。

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
        }
    }
}

適用於