Contextual Trigger
Tizen enables you to define rules as a combination of a contextual event, conditions, and an action. When the rule is enabled, the system starts to monitor the device status or user activities corresponding to the event defined in the rule. When the event is detected, the conditions are evaluated, and if the conditions are met, the action is triggered.
This feature is supported in mobile applications only.
The action can be an application launching request using an App Control, or a notification posting. For example, every day at 10:00 PM, if the battery level is low, the application can post a notification to remind the user to charge the battery.
The main features of the Contextual Trigger API include:
- Life-cycle management
Once a rule is composed and registered successfully into the system, a unique rule ID is assigned to it. You can use the rule ID to enable, disable, or permanently remove the rule.
Figure: Rule states
Note A rule can be enabled, disabled, or removed only by the owner application that composed and registered the rule. - Rule retrieval
The application can retrieve a list of enabled and disabled rule IDs owned by the application.
If you only need to monitor a fundamental system event, such as the USB connection status, to launch a service application, and no condition is required, use event callbacks. In these cases, using the event system instead of the contextual trigger is more efficient, as the contextual trigger runs a rule engine to manage state changes of multiple event and condition items simultaneously.
A rule always consist of 3 main components:
- Event
An event literally denotes a contextual event that can be recognized by the device, or a change in a certain contextual state of the device or the user. For example, connections to peripherals, changes in settings, location changes, or specific times can be used as events. Note that only 1 event can be defined in a rule, as it is used as the initiator of the verification of the conditions. If the system detects the occurrence of the designated event, it starts to verify the conditions.
- Condition
A condition denotes a contextual state or fact that can be recognized by the device. For example, the current device status or the historical pattern of the device usage can be used as conditions. In a rule, the application can define 1 condition, multiple conditions, or even no condition. If you define multiple conditions in a rule, the application can choose the way of combining the conditions using logical conjunctions or disjunctions. In case of the logical conjunction, the rule is true only if all the conditions are met. Otherwise, the rule can be true if at least 1 condition is met. If no condition is given, the rule is satisfied instantly when the corresponding event occurs.
- Action
An action is triggered when the rule is satisfied. Each rule must basically contain 1 action only. However, because the action itself can be defined as an App Control, if necessary, you can implement an application that executes a series of tasks to create a complex context-aware service.
The following figure illustrates the rule components and their relations.
Figure: Rule components
Event and Conditions
In a rule, the combination of an event and conditions formulates the logical statement that decides to execute the action of the rule or leave it undone. The event and the conditions are defined in various kinds of contextual information, which can be recognized on the device:
- An event represents a contextual state change or a contextual event literally, such as "headphone is plugged", "the battery level has dropped to low", or "the user enters his home".
- A condition represents a current contextual state or a device or user profile inferred through the usage history, for example, "the current battery level is low", "Wi-Fi connection is active", or "(when receiving an incoming call) the number is the most frequent address in his call logs".
Defining an event or a condition can involve attribute comparisons and input option parameter settings. The following example illustrates how to formulate a simple rule of "at 10 PM, if the battery is not charging":
- Create a rule handle. The first parameter (CONTEXT_TRIGGER_LOGICAL_CONJUNCTION) denotes how to combine all condition entries.
context_trigger_rule_h rule = NULL; context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &rule);
- Define the event ("at 10 PM every day").
A CONTEXT_TRIGGER_EVENT_TIME type event entry is created, and a key-value comparison of CONTEXT_TRIGGER_TIME_OF_DAY == 1320 is set to the event.
// Composing an event context_trigger_rule_entry_h event = NULL; context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_TIME, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_TIME_OF_DAY); context_trigger_rule_entry_add_comparison_int(event, CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_EQUAL_TO, 1320); // Adding the event to the rule and releasing the resources context_trigger_rule_add_entry(rule, event); context_trigger_rule_entry_destroy(event);
- Formulate the condition statement ("battery is not charging") and add it to the rule handle.
In the condition entry of CONTEXT_TRIGGER_CONDITION_BATTERY, the comparison statement is defined as the equality check (CONTEXT_TRIGGER_EQUAL_TO) between the left operand (CONTEXT_TRIGGER_IS_CHARGING) and the right operand (CONTEXT_TRIGGER_FALSE).
// Composing a condition context_trigger_rule_entry_h condition = NULL; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition); context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_IS_CHARGING); context_trigger_rule_entry_add_comparison_int(condition, CONTEXT_TRIGGER_IS_CHARGING, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_FALSE); // Adding the condition to the rule handle context_trigger_rule_add_entry(rule, condition); context_trigger_rule_entry_destroy(condition);
The above example rule only contains 1 condition, and both the event and the condition contain 1 key-value comparison each. More complex rules, with multiple conditions and multiple comparisons in the event and each condition, can be also formulated. In addition, certain events and conditions require you to set option parameters.
Comparison Attributes for Events and Conditions
The following table summarizes the corresponding comparison attribute keys, with respect to the event and condition items, and the valid right operands for each attribute key. For information on the necessary privileges for each item, see the Contextual Trigger API.
Event or condition | Attribute key | Type | Valid operands |
---|---|---|---|
CONTEXT_TRIGGER_EVENT_TIME | CONTEXT_TRIGGER_TIME_OF_DAY | Integer | From 0 to 1439 (minute) |
CONTEXT_TRIGGER_DAY_OF_WEEK | String | CONTEXT_TRIGGER_MON, CONTEXT_TRIGGER_TUE, CONTEXT_TRIGGER_WED, CONTEXT_TRIGGER_THU, CONTEXT_TRIGGER_FRI, CONTEXT_TRIGGER_SAT, CONTEXT_TRIGGER_SUN, CONTEXT_TRIGGER_WEEKDAY, CONTEXT_TRIGGER_WEEKEND | |
CONTEXT_TRIGGER_CONDITION_TIME | CONTEXT_TRIGGER_TIME_OF_DAY | Integer | From 0 to 1439 (minute) |
CONTEXT_TRIGGER_DAY_OF_WEEK | String | CONTEXT_TRIGGER_MON, CONTEXT_TRIGGER_TUE, CONTEXT_TRIGGER_WED, CONTEXT_TRIGGER_THU, CONTEXT_TRIGGER_FRI, CONTEXT_TRIGGER_SAT, CONTEXT_TRIGGER_SUN, CONTEXT_TRIGGER_WEEKDAY, CONTEXT_TRIGGER_WEEKEND | |
CONTEXT_TRIGGER_DAY_OF_MONTH | Integer | From 1 to 31 | |
CONTEXT_TRIGGER_EVENT_CHARGER
CONTEXT_TRIGGER_EVENT_USB CONTEXT_TRIGGER_CONDITION_CHARGER CONTEXT_TRIGGER_CONDITION_USB |
CONTEXT_TRIGGER_IS_CONNECTED | Integer | CONTEXT_TRIGGER_TRUE, CONTEXT_TRIGGER_FALSE |
CONTEXT_TRIGGER_EVENT_BATTERY
CONTEXT_TRIGGER_CONDITION_BATTERY |
CONTEXT_TRIGGER_LEVEL | String | CONTEXT_TRIGGER_EMPTY, CONTEXT_TRIGGER_CRITICAL, CONTEXT_TRIGGER_LOW, CONTEXT_TRIGGER_NORMAL, CONTEXT_TRIGGER_HIGH, CONTEXT_TRIGGER_FULL |
CONTEXT_TRIGGER_IS_CHARGING | Integer | CONTEXT_TRIGGER_TRUE, CONTEXT_TRIGGER_FALSE | |
CONTEXT_TRIGGER_EVENT_POWER_SAVING_MODE CONTEXT_TRIGGER_CONDITION_POWER_SAVING_MODE |
CONTEXT_TRIGGER_IS_ENABLED | Integer | CONTEXT_TRIGGER_TRUE, CONTEXT_TRIGGER_FALSE |
CONTEXT_TRIGGER_EVENT_GPS
CONTEXT_TRIGGER_CONDITION_GPS |
CONTEXT_TRIGGER_STATE | String | CONTEXT_TRIGGER_DISABLED, CONTEXT_TRIGGER_SEARCHING, CONTEXT_TRIGGER_CONNECTED |
CONTEXT_TRIGGER_EVENT_HEADPHONE
CONTEXT_TRIGGER_CONDITION_HEADPHONE |
CONTEXT_TRIGGER_IS_CONNECTED | Integer | CONTEXT_TRIGGER_TRUE, CONTEXT_TRIGGER_FALSE |
CONTEXT_TRIGGER_TYPE | String | CONTEXT_TRIGGER_NORMAL, CONTEXT_TRIGGER_HEADSET, CONTEXT_TRIGGER_BLUETOOTH | |
CONTEXT_TRIGGER_EVENT_WIFI
CONTEXT_TRIGGER_CONDITION_WIFI |
CONTEXT_TRIGGER_STATE | String | CONTEXT_TRIGGER_DISABLED, CONTEXT_TRIGGER_CONNECTED, CONTEXT_TRIGGER_UNCONNECTED |
CONTEXT_TRIGGER_BSSID | String | Wi-Fi BSSID | |
CONTEXT_TRIGGER_EVENT_CALL
CONTEXT_TRIGGER_CONDITION_CALL |
CONTEXT_TRIGGER_STATE | String | CONTEXT_TRIGGER_IDLE, CONTEXT_TRIGGER_CONNECTING, CONTEXT_TRIGGER_CONNECTED |
CONTEXT_TRIGGER_MEDIUM | String | CONTEXT_TRIGGER_VOICE, CONTEXT_TRIGGER_VIDEO | |
CONTEXT_TRIGGER_ADDRESS | String | Phone number | |
CONTEXT_TRIGGER_EVENT_EMAIL | CONTEXT_TRIGGER_EVENT | String | CONTEXT_TRIGGER_RECEIVED, CONTEXT_TRIGGER_SENT |
CONTEXT_TRIGGER_EVENT_MESSAGE | CONTEXT_TRIGGER_EVENT | String | CONTEXT_TRIGGER_RECEIVED |
CONTEXT_TRIGGER_TYPE | String | CONTEXT_TRIGGER_SMS, CONTEXT_TRIGGER_MMS | |
CONTEXT_TRIGGER_EVENT_ACTIVITY_STATIONARY
CONTEXT_TRIGGER_EVENT_ACTIVITY_WALKING CONTEXT_TRIGGER_EVENT_ACTIVITY_RUNNING CONTEXT_TRIGGER_EVENT_ACTIVITY_IN_VEHICLE |
CONTEXT_TRIGGER_EVENT | String | CONTEXT_TRIGGER_DETECTED |
CONTEXT_TRIGGER_ACCURACY | String | CONTEXT_TRIGGER_HIGH, CONTEXT_TRIGGER_NORMAL, CONTEXT_TRIGGER_LOW | |
CONTEXT_TRIGGER_EVENT_PLACE | CONTEXT_TRIGGER_EVENT | String | CONTEXT_TRIGGER_IN, CONTEXT_TRIGGER_OUT |
CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY
CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY |
CONTEXT_TRIGGER_RANK | Integer | Positive integer |
CONTEXT_TRIGGER_TOTAL_COUNT | Integer | Non-negative integer | |
CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY
CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY |
CONTEXT_TRIGGER_TOTAL_COUNT | Integer | Non-negative integer |
The following comparison operators are allowed for specific attribute data types:
- For integer-type attributes:
- CONTEXT_TRIGGER_EQUAL_TO
- CONTEXT_TRIGGER_NOT_EQUAL_TO
- CONTEXT_TRIGGER_GREATER_THAN
- CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO
- CONTEXT_TRIGGER_LESS_THAN
- CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO
- For string-type attributes:
- CONTEXT_TRIGGER_EQUAL_TO
- CONTEXT_TRIGGER_NOT_EQUAL_TO
Options
Certain events or conditions require the specification of some option values to clarify their monitoring or computation objective. For example, if an event is defined using CONTEXT_TRIGGER_EVENT_PLACE, the target place must be specified by its ID that can be retrieved using the Geofence Manager, as in the following example:
int place_id; // The target place ID must be retrieved through the Geofence Manager API // Composing an event "when the user enters his home" context_trigger_rule_entry_h event = NULL; context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_PLACE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); context_trigger_rule_entry_add_option_int(event, CONTEXT_TRIGGER_PLACE_ID, place_id);
You can also use an attribute value of the event as an option (or a right operand of a comparison) in a condition. As an example, the logical statement "when receiving a message, if the sender's number is the most frequently communicated number" can be formulated as follows:
// Composing an event "when receiving a message" context_trigger_rule_entry_h event = NULL; context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_MESSAGE, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &event); context_trigger_rule_entry_add_key(event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_EVENT); context_trigger_rule_entry_add_comparison_string(event, CONTEXT_TRIGGER_EVENT, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_RECEIVED); // Composing a condition "if the sender's number is the most frequently communicated number" context_trigger_rule_entry_h condition = NULL; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &condition); // The message sender's address is used as an option of the condition. context_trigger_rule_entry_add_option(condition, CONTEXT_TRIGGER_ADDRESS, CONTEXT_TRIGGER_ADDRESS); // Checking if the frequency rank of the address is equal to 1 context_trigger_rule_entry_add_key(condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_RANK); context_trigger_rule_entry_add_comparison_int(condition, CONTEXT_TRIGGER_RANK, CONTEXT_TRIGGER_EQUAL_TO, 1);
The following table lists the available options keys and the corresponding values.
Event or condition | Option key | Type | Valid value |
---|---|---|---|
CONTEXT_TRIGGER_EVENT_PLACE | CONTEXT_TRIGGER_PLACE_ID | Integer | Place ID. For more information, see the Geofence guide. |
CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY | CONTEXT_TRIGGER_APP_ID | String | Application ID |
CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY | CONTEXT_TRIGGER_ADDRESS | String | Phone number |
CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY
CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY |
CONTEXT_TRIGGER_TIME_OF_DAY | String | Time interval of the day. For example, "13-15" denotes "from 1 PM to 3 PM". |
CONTEXT_TRIGGER_DAY_OF_WEEK | String | CONTEXT_TRIGGER_MON, CONTEXT_TRIGGER_TUE, CONTEXT_TRIGGER_WED, CONTEXT_TRIGGER_THU, CONTEXT_TRIGGER_FRI, CONTEXT_TRIGGER_SAT, CONTEXT_TRIGGER_SUN, CONTEXT_TRIGGER_WEEKDAY, CONTEXT_TRIGGER_WEEKEND |
Logical Conjunctions and Disjunctions
A rule can contain multiple conditions. Some event and condition items provide more than 1 attribute key. For 1 attribute, more than 1 comparison statement can also be defined. For example, the value of an attribute is equal to A, B, or C. To combine multiple comparisons into an attribute, multiple attributes into an event or a condition, and multiple conditions into a rule, the contextual trigger allows you to choose 1 of the following logical operators:
-
CONTEXT_TRIGGER_LOGICAL_CONJUNCTION
It denotes logical "AND". It means "true only if all components are true".
-
CONTEXT_TRIGGER_LOGICAL_DISJUNCTION
It denotes logical "OR". It means "true if at least 1 component is true".
To use the conjunctions and disjunctions:
- Combining conditions into a rule
With the logical conjunction operator, the rule evaluation becomes true if all the conditions are met. On the other hand, with the logical disjunction operator, the rule evaluation becomes true if at least 1 of the conditions is met. If a rule has 1 condition or no condition, the logical operator has no effect on the evaluation result. The following example shows how to set the proper logical operator between conditions when creating rules:
// Composing an event and conditions context_trigger_rule_entry_h battery_event; context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &battery_event); context_trigger_rule_entry_add_key(battery_event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_LEVEL); context_trigger_rule_entry_add_comparison_string(battery_event, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_CRITICAL); context_trigger_rule_entry_h gps_condition; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_GPS, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &gps_condition); context_trigger_rule_entry_add_key(gps_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_STATE); context_trigger_rule_entry_add_comparison_string(gps_condition, CONTEXT_TRIGGER_STATE, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_DISABLED); context_trigger_rule_entry_h wifi_condition; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_WIFI, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &wifi_condition); context_trigger_rule_entry_add_key(wifi_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_STATE); context_trigger_rule_entry_add_comparison_string(wifi_condition, CONTEXT_TRIGGER_STATE, CONTEXT_TRIGGER_NOT_EQUAL_TO, CONTEXT_TRIGGER_DISABLED); // Composing a rule "when the battery level becomes critical, if GPS AND Wi-Fi are enabled" context_trigger_rule_h conjunction_rule; context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &conjunction_rule); context_trigger_rule_add_entry(conjunction_rule, battery_event); context_trigger_rule_add_entry(conjunction_rule, gps_condition); context_trigger_rule_add_entry(conjunction_rule, wifi_condition); context_trigger_rule_set_action_notification(conjunction_rule, ...); // Composing a rule "when battery level becomes critical, if GPS OR Wi-Fi is enabled" context_trigger_rule_h disjunction_rule; context_trigger_rule_create(CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &disjunction_rule); context_trigger_rule_add_entry(disjunction_rule, battery_event); context_trigger_rule_add_entry(disjunction_rule, gps_condition); context_trigger_rule_add_entry(disjunction_rule, wifi_condition); context_trigger_rule_set_action_notification(disjunction_rule, ...);
- Combining attributes into an event or condition
Some event and condition items provide multiple attributes. The logical connection between attributes must be set properly to fulfill the requirement. For example, when you use CONTEXT_TRIGGER_EVENT_TIME to define a rule "at 4 PM every Monday", the comparisons regarding the 2 attributes, CONTEXT_TRIGGER_TIME_OF_DAY and CONTEXT_TRIGGER_DAY_OF_WEEK must be satisfied together.
On the contrary, using CONTEXT_TRIGGER_APP_USE_FREQUENCY, if you want to check whether a specific application belongs to the 5 most frequently used applications, or the application was used at least 10 times, both comparisons against CONTEXT_TRIGGER_RANK and CONTEXT_TRIGGER_TOTAL_COUNT must be connected by a logical disjunction.
The following example illustrates the cases described above:
// Composing an event "at 4 PM every Monday" context_trigger_rule_entry_h time_event; context_trigger_rule_event_create(CONTEXT_TRIGGER_EVENT_TIME, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &time_event); context_trigger_rule_entry_add_key(time_event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_TIME_OF_DAY); context_trigger_rule_entry_add_comparison_int(time_event, CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_EQUAL_TO, 960); context_trigger_rule_entry_add_key(time_event, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_DAY_OF_WEEK); context_trigger_rule_entry_add_comparison_string(time_event, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_MON); // Composing a condition "if an application belongs to the 5 most frequently used apps, or is used at least 10 times per day" context_trigger_rule_entry_h app_condition; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, &app_condition); context_trigger_rule_entry_add_option_string(app_condition, CONTEXT_TRIGGER_APP_ID, /* Application ID */); context_trigger_rule_entry_add_key(app_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_RANK); context_trigger_rule_entry_add_comparison_int(app_condition, CONTEXT_TRIGGER_RANK, CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO, 5); context_trigger_rule_entry_add_key(app_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_TOTAL_COUNT); context_trigger_rule_entry_add_comparison_int(app_condition, CONTEXT_TRIGGER_TOTAL_COUNT, CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO, 10);
- Combining comparisons into an attribute
Similarly as above, regarding an attribute, you can combine multiple comparisons in different ways. For example, if you want to check that the battery level is full or high, use a logical disjunction. If you also want to check whether the current time is between 18:30 and 21:30, use a logical conjunction. The following example illustrates how to compose such conditions:
// Composing a condition "if the battery level is full or high" context_trigger_rule_entry_h battery_condition; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_BATTERY, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &battery_condition); context_trigger_rule_entry_add_key(battery_condition, CONTEXT_TRIGGER_LOGICAL_DISJUNCTION, CONTEXT_TRIGGER_LEVEL); context_trigger_rule_entry_add_comparison_string(battery_condition, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_FULL); context_trigger_rule_entry_add_comparison_string(battery_condition, CONTEXT_TRIGGER_LEVEL, CONTEXT_TRIGGER_EQUAL_TO, CONTEXT_TRIGGER_HIGH); // Composing a condition "if the current time is between 18:30 and 21:30" context_trigger_rule_entry_h time_condition; context_trigger_rule_condition_create(CONTEXT_TRIGGER_CONDITION_TIME, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, &time_condition); context_trigger_rule_entry_add_key(time_condition, CONTEXT_TRIGGER_LOGICAL_CONJUNCTION, CONTEXT_TRIGGER_TIME_OF_DAY); context_trigger_rule_entry_add_comparison_int(time_condition, CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_GREATER_THAN_OR_EQUAL_TO, 1110); context_trigger_rule_entry_add_comparison_int(time_condition, CONTEXT_TRIGGER_TIME_OF_DAY, CONTEXT_TRIGGER_LESS_THAN_OR_EQUAL_TO, 1290);
Actions
When a rule is satisfied (the event has occurred and the conditions are met), the corresponding action is triggered. Only 1 action can be set for a rule, and the action can be one of the following:
- Application launch request:
The contextual trigger allows you to set an App Control as an action. You can utilize the app control functionalities by developing an application with the corresponding app controls to execute a series of tasks when a rule is satisfied.
- Notification posting:
A basic form of notification can be set as an action. A notification can contain a title, content body text, an icon, and an app control to be executed. For more information, see the Notification guide.