Page Example

Context History Sample Overview

Mobile native

The Context History sample application demonstrates how you can retrieve device usage statistics using the Contextual History API.

The following figure shows the main screens of the Context History sample application.

Figure: Context History screens

Context History screens Context History screens

The application opens with the main screen that shows the presets of usage statistics. The corresponding history item and the filter values are set differently on each preset.

To retrieve the corresponding usage statistics, if available, select a preset. For example, if you select the second preset from the top, the screen lists the top 7 frequently used applications during the last 30 days, only considering the applications used while a headphone is connected.

Some presets do not show any results if there are no usage logs available yet.


To ensure proper application execution, the following privileges must be set:

  • To access call history:
  • To access application history:
  • To access media history:
  • To get the current Wi-Fi BSSID that is used as a filter value of one preset:


The application is initialized within the app_create() callback function. The following example shows how to use the Contextual History API to retrieve usage statistics in the history module: the get_frequently_used_apps() function retrieves the CONTEXT_HISTORY_FREQUENTLY_USED_APP statistics with 3 filtering options (timespan of the logs to be processed, result size, and audio jack status).

get_frequently_used_apps(void *data EINA_UNUSED, Evas_Object * obj EINA_UNUSED, void *event_info)
   context_history_h history_h = NULL;
   context_history_list_h list_h = NULL;
   context_history_record_h record_h = NULL;
   context_history_filter_h filter_h = NULL;

   int record_count = 0;
   char* app_id = NULL;
   int total_count = -1;
   int total_duration = -1;
   int last_time = -1;

   // Create history handle

   // Create filter handle

   // Set a filtering option: audio jack status

   // Set a filtering option: timespan
   context_history_filter_set_int(filter_h, CONTEXT_HISTORY_FILTER_TIME_SPAN, 30);

   // Set a filtering option: result size
   context_history_filter_set_int(filter_h, CONTEXT_HISTORY_FILTER_RESULT_SIZE, 7);

   // Get the statistics
   context_history_get_list(history_h, CONTEXT_HISTORY_FREQUENTLY_USED_APP, filter_h, &list_h);

   // Get the number of records in the retrieved list (may not be equal to the given filter)
   context_history_list_get_count(list_h, &record_count);

   // Extract records from list
   for (int i = 0; i < record_count; i++)
      // Get the current record from the list
      context_history_list_get_current(list_h, &record_h);

      // Get an attribute: App ID
      context_history_record_get_string(record_h, CONTEXT_HISTORY_APP_ID, &app_id);

      // Get an attribute: Total count of use
      context_history_record_get_int(record_h, CONTEXT_HISTORY_TOTAL_COUNT, &total_count);

      // Get an attribute: Total duration of use
      context_history_record_get_int(record_h, CONTEXT_HISTORY_TOTAL_DURATION, &total_duration);

      // Get an attribute: Last time of use
      context_history_record_get_int(record_h, CONTEXT_HISTORY_LAST_TIME, &last_time);

      // Use the retrieved attributes

      // Free the string attributes
      app_id = NULL;
      total_count = -1;
      total_duration = -1;
      last_time = -1;

      // Destroy the record handle
      record_h = NULL;

      // Move to the next record


   // Destroy the list handle

   // Destroy the filter handle

   // Destroy the history handle