Notification from watchface app within a time interval
Use below code snippet to give notification from the watchface app within a certain time period. In this code snippet time interval is set to three minutes.
#include <watch_app.h>
#include <notification.h>
<privilege>http://tizen.org/privilege/notification</privilege>
/* define globally */
notification_h notification = NULL;
int count = 0;
static void
update_watch(appdata_s *ad, watch_time_h watch_time, int ambient)
{
char watch_text[TEXT_BUF_SIZE];
int hour24, minute, second;
if (watch_time == NULL)
return;
notification_h notification = NULL;
watch_time_get_hour24(watch_time, &hour24);
watch_time_get_minute(watch_time, &minute);
watch_time_get_second(watch_time, &second);
if (!ambient) {
/* increase counter value to check time interval */
if(second == 0) count++;
if(count == 3){
dlog_print(DLOG_INFO, LOG_TAG, " Give Notification");
/* create notification */
notification = notification_create(NOTIFICATION_TYPE_NOTI);
int ret =0;
ret = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, "Notification!!", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
ret = notification_post(notification);
notification_free(notification);
/* set counter to zero for next interval */
count = 0;
}
dlog_print(DLOG_INFO, LOG_TAG, "cnt = %d", count);
snprintf(watch_text, TEXT_BUF_SIZE, "<align=center>Hello<br/>%02d:%02d:%02d</align>",
hour24, minute, second);
} else {
snprintf(watch_text, TEXT_BUF_SIZE, "<align=center>Hello Watch<br/>%02d:%02d</align>",
hour24, minute);
}
elm_object_text_set(ad->label, watch_text);
}