Application Usage History Data

You can retrieve the user’s application usage patterns, such as information about frequently used applications.

The main features of the Tizen.Context.AppHistory namespace are:

Prerequisites

To enable your application to use the application usage history data functionality:

  1. To use the Tizen.Context.AppHistory namespace, the application has to request permission by adding the following privilege to the tizen-manifest.xml file:

    XML
    Copy
    <privileges> <privilege>http://tizen.org/privilege/apphistory.read</privilege> </privileges>
  2. To use the methods and properties of the Tizen.Context.AppHistory namespace, include it in your application:

    C#
    Copy
    using Tizen.Context.AppHistory;

Retrieving Application Usage Statistics

To retrieve application usage statistics for a given time period, and check detailed statistics information, such as duration, launch count, and last launch time of the used applications:

  1. To retrieve the application launch history, create a usage statistics instance:

    • To use the default LaunchCountMost sort order, create a new instance of the Tizen.Context.AppHistory.UsageStatistics class without specifying the sortOrder parameter:

      C#
      Copy
      UsageStatistics frequentlyUsedApp = new UsageStatistics();
    • To use another sort order for your usage statistics instance, add the sortOrder parameter to the Tizen.Context.AppHistory.UsageStatistics class constructor, using values of the Tizen.Context.AppHistory.UsageStatistics.SortOrderType enumeration:

      C#
      Copy
      UsageStatistics recentlyUsedApp = new UsageStatistics(UsageStatistics.SortOrderType.LastLaunchTimeNewest);
  2. To get information about the most frequently used applications for a given time period, use the Query() method of the Tizen.Context.AppHistory.UsageStatistics class:

    • To retrieve a list of frequently used applications for a given time period, specify the startTime and the endTime parameters to determine the time period.

      For example, to retrieve a list of the most frequently used applications for the last 2 weeks:

      C#
      Copy
      IReadOnlyList<UsageStatisticsData> frequentlyUsedAppList = frequentlyUsedApp.Query(DateTime.Now.AddDays(-14), DateTime.Now);
    • By default, the query returns a maximum of 10 results. You can change the number of returned results by setting the resultSize parameter.

      For example, to retrieve a list of 5 most frequently used applications for the last 2 weeks:

      C#
      Copy
      IReadOnlyList<UsageStatisticsData> frequentlyUsedAppList = frequentlyUsedApp.Query(DateTime.Now.AddDays(-14), DateTime.Now, 5);
    • The query returns a sorted list of Tizen.Context.AppHistory.UsageStatisticsData class instances. To enumerate the list:

      C#
      Copy
      foreach(var record in frequentlyUsedAppList) { Log.Info(LOGTAG, "AppId: " + record.AppId); Log.Info(LOGTAG, "Duration: " + record.Duration); Log.Info(LOGTAG, "LaunchCount: " + record.LaunchCount); Log.Info(LOGTAG, "LastLaunchTime: " + record.LastLaunchTime); }

Retrieving Battery Usage Statistics

To retrieve battery usage statistics for a given time period, and check detailed statistics information, such as the battery consumption of the used applications:

  1. To retrieve the battery consumption per application, create an instance of the Tizen.Context.AppHistory.BatteryStatistics class:

    C#
    Copy
    BatteryStatistics batteryConsumedApp = new BatteryStatistics(BatteryStatistics.SortOrderType.ConsumptionMost);
  2. To get the information about the application battery consumption, use Query() of the Tizen.Context.AppHistory.BatteryStatistics class.

    For example, to retrieve battery consumption history since the device was last fully charged, use a DateTime instance returned by GetLastFullyChargedTime() as the startTime parameter of Query():

    C#
    Copy
    DateTime time = BatteryStatistics.GetLastFullyChargedTime(); IReadOnlyList<BatteryStatisticsData> batteryConsumedAppList = batteryConsumedApp.Query(time, DateTime.Now, 5);
  3. The Query() returns a sorted list of Tizen.Context.AppHistory.BatteryStatisticsData class instances. To enumerate the list:

    C#
    Copy
    foreach(var record in batteryConsumedAppList) { Log.Info(LOGTAG, "AppId: " + record.AppId); Log.Info(LOGTAG, "Consumption: " + record.Consumption); }
  • Dependencies
    • Tizen 4.0 and Higher
OAuth 2.0
Next Alarms
Submit your feedback to GitHub