【问题标题】:Hourly alert (chime) in Gear S3Gear S3 中的每小时警报(铃声)
【发布时间】:2017-07-15 20:39:55
【问题描述】:

如何在 Gear S3 的原生表盘应用程序中进行每小时提醒? 有代码示例吗?

【问题讨论】:

  • 您是否在表盘应用程序的 tizen-manifest.xml 文件中添加了以下行? tizen.org/privilege/alarm.get</privilege> tizen.org/privilege/alarm.set</privilege>
  • 是的,我做到了。这些行位于表盘应用程序的 tizen-manifest.xml 中。
  • 使用清单文件中的代码编辑问题。我没有收到这样的错误。我猜你错过了任何步骤。
  • 我为应用程序和服务添加了两个清单文件。
  • 我已经编辑了我的答案,请检查。

标签: tizen


【解决方案1】:

您可以尝试为此目的使用警报 API。请按照以下步骤操作:

  1. 首先创建一个Watch Application 和一个Service Application。打包两个应用程序并构建。通过this link 进行包装。
  2. 现在在表盘应用程序中使用以下代码 sn-p 在特定时间(在您的情况下为 1 小时)后触发警报。

    bool init_alert(){
    int ret;
    int DELAY = 3;
    int REMIND = 3600; //alert after every 1hr.
    int alarm_id;
    
    app_control_h app_control = NULL;
    ret = app_control_create(&app_control);
    ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
    ret = app_control_set_app_id(app_control, "Service_App_ID");
    ret = alarm_schedule_after_delay(app_control, DELAY, REMIND, &alarm_id);
    
    return true;}
    

    在表盘应用清单文件中使用以下权限:

    http://tizen.org/privilege/alarm.get

    http://tizen.org/privilege/alarm.set

  3. 现在在服务应用程序的 service_app_control() 函数中,使用以下代码创建警报:

    void service_app_control(app_control_h app_control, void *data){
    
    dlog_print(DLOG_INFO, LOG_TAG, "Hourly Alert Here");
    notification = notification_create(NOTIFICATION_TYPE_NOTI);
    int ret =0;
    ret = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, "Hourly Alert!!",
                                NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
    ret = notification_post(notification);
    notification_free(notification);
    return;}
    

在服务应用清单文件中使用以下权限:

http://tizen.org/privilege/notification

欲知详情,请通过this link

编辑:1 您可以在this link 中找到此问题的原因。请浏览备注另见部分。我之前已经发布了 2.3.2 版的答案。这就是为什么我没有收到任何错误。 请按照下面的方法。就我而言,它适用于 3.0 版。

第 1 步: 取一个计数器,首先将其设置为 0,并在每次时钟为 0 秒时递增,如下所示:

watch_time_get_second(watch_time, &second);
if(second == 0) count++;

第 2 步: 现在,检查计数器值是否等于您所需的值,例如如果您希望每 3 分钟间隔后发出警报,则可以检查它是否等于 3,然后创建如下通知:

if(count == 3){
            dlog_print(DLOG_INFO, LOG_TAG, "Hourly Alert");
            notification = notification_create(NOTIFICATION_TYPE_NOTI);

            int ret =0;
            ret = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, "Hourly Alert!!",
                    NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
            ret = notification_post(notification);
            notification_free(notification);
            count = 0;
        }

最后,将计数器设置为 0,准备好为下一个间隔计数。找到下面的完整代码结构以便更好地理解:

#include <notification.h>
static 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;

    watch_time_get_hour24(watch_time, &hour24);
    watch_time_get_minute(watch_time, &minute);
    watch_time_get_second(watch_time, &second);

    if (!ambient) {
        if(second == 0) count++;

        if(count == 3){
            dlog_print(DLOG_INFO, LOG_TAG, "Hourly Alert");
            notification = notification_create(NOTIFICATION_TYPE_NOTI);

            int ret =0;
            ret = notification_set_text(notification, NOTIFICATION_TEXT_TYPE_TITLE, "Hourly Alert!!",
                    NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
            ret = notification_post(notification);
            notification_free(notification);
            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);
}

注意:不要忘记添加通知权限。

【讨论】:

  • 谢谢!但是 alarm_schedule_after_delay() 返回 ALARM_ERROR_NOT_PERMITTED_APP,这意味着 - 如果 app_control 不是 UI 应用程序,则返回 ALARM_ERROR_NOT_PERMITTED_APP。 (description)。如何解决?
  • 从指南来看,alarm_schedule_after_delay 的 app_control 需要使用服务应用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多