Application Usage History Data
PUBLISHED
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:
- Retrieving application usage statistics
You can retrieve application launch history, such as frequently used applications and recently used applications, using the Tizen.Context.AppHistory.UsageStatistics [1] class.
- Retrieving battery usage statistics
You can retrieve battery usage statistics, using the Tizen.Context.AppHistory.BatteryStatistics [2] class.
Prerequisites
To enable your application to use the application usage history data functionality:
- To use the Tizen.Context.AppHistory [3] namespace, the application has to request permission by adding the following privilege to the
tizen-manifest.xml
file:<privileges> <privilege>http://tizen.org/privilege/apphistory.read</privilege> </privileges>
- To use the methods and properties of the Tizen.Context.AppHistory namespace, include it in your application:
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:
- 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 [1] class without specifying thesortOrder
parameter:UsageStatistics frequentlyUsedApp = new UsageStatistics();
- To use another sort order for your usage statistics instance, add the
sortOrder
parameter to theTizen.Context.AppHistory.UsageStatistics
class constructor, using values of the Tizen.Context.AppHistory.UsageStatistics.SortOrderType [4] enumeration:
UsageStatistics recentlyUsedApp = new UsageStatistics(UsageStatistics.SortOrderType.LastLaunchTimeNewest);
- To use the default
- To get information about the most frequently used applications for a given time period, use the
Query()
method of theTizen.Context.AppHistory.UsageStatistics
class:- To retrieve a list of frequently used applications for a given time period, specify the
startTime
and theendTime
parameters to determine the time period.For example, to retrieve a list of the most frequently used applications for the last 2 weeks:
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:
IReadOnlyList<UsageStatisticsData> frequentlyUsedAppList = frequentlyUsedApp.Query(DateTime.Now.AddDays(-14), DateTime.Now, 5);
- The query returns a sorted list of Tizen.Context.AppHistory.UsageStatisticsData [5] class instances. To enumerate the list:
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); }
- To retrieve a list of frequently used applications for a given time period, specify the
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:
- To retrieve the battery consumption per application, create an instance of the Tizen.Context.AppHistory.BatteryStatistics [2] class:
BatteryStatistics batteryConsumedApp = new BatteryStatistics(BatteryStatistics.SortOrderType.ConsumptionMost);
- To get the information about the application battery consumption, use the
Query()
method of theTizen.Context.AppHistory.BatteryStatistics
class.For example, to retrieve battery consumption history since the device was last fully charged, use a
DateTime
instance returned by theGetLastFullyChargedTime()
method as thestartTime
parameter of theQuery()
method:DateTime time = BatteryStatistics.GetLastFullyChargedTime(); IReadOnlyList<BatteryStatisticsData> batteryConsumedAppList = batteryConsumedApp.Query(time, DateTime.Now, 5);
- The
Query()
method returns a sorted list of Tizen.Context.AppHistory.BatteryStatisticsData [6] class instances. To enumerate the list:
foreach(var record in batteryConsumedAppList) { Log.Info(LOGTAG, "AppId: " + record.AppId); Log.Info(LOGTAG, "Consumption: " + record.Consumption); }