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 as follows:
-
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 class.
-
Retrieving battery usage statistics
You can retrieve battery usage statistics using the Tizen.Context.AppHistory.BatteryStatistics class.
Prerequisites
To enable your application to use the application usage history data functionality, follow these steps:
-
To use the Tizen.Context.AppHistory namespace, the application has to request permission by adding the following privilege to the
tizen-manifest.xml
file:XMLCopy<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:
C#Copyusing Tizen.Context.AppHistory;
Retrieve application usage statistics
To retrieve application usage statistics for a given time period, and to check detailed statistics information, such as duration, launch count, and last launch time of the used applications, follow these steps:
-
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 thesortOrder
parameter:C#CopyUsageStatistics 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 enumeration:C#CopyUsageStatistics recentlyUsedApp = new UsageStatistics(UsageStatistics.SortOrderType.LastLaunchTimeNewest);
-
-
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:
C#CopyIReadOnlyList<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#CopyIReadOnlyList<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#Copyforeach(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); }
-
Retrieve 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, follow these steps:
-
To retrieve the battery consumption per application, create an instance of the Tizen.Context.AppHistory.BatteryStatistics class:
C#CopyBatteryStatistics batteryConsumedApp = new BatteryStatistics(BatteryStatistics.SortOrderType.ConsumptionMost);
-
To get the information about the application battery consumption, use
Query()
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 byGetLastFullyChargedTime()
as thestartTime
parameter ofQuery()
:C#CopyDateTime time = BatteryStatistics.GetLastFullyChargedTime(); IReadOnlyList<BatteryStatisticsData> batteryConsumedAppList = batteryConsumedApp.Query(time, DateTime.Now, 5);
-
The
Query()
returns a sorted list of Tizen.Context.AppHistory.BatteryStatisticsData class instances. To enumerate the list:C#Copyforeach(var record in batteryConsumedAppList) { Log.Info(LOGTAG, "AppId: " + record.AppId); Log.Info(LOGTAG, "Consumption: " + record.Consumption); }
Related information
- Dependencies
- Tizen 4.0 and Higher