2017-07-15 33 views
-1

如何在Gear S3原生錶盤應用程序中每小時發出一次警報? 任何代碼示例?Gear S3,Tizen:原生應用程序中的每小時警報(鐘聲)

感謝您的任何信息!

+0

您是否在表格應用程序的tizen-manifest.xml文件中添加了以下行? http:// tizen。org/privilege/alarm.get http://tizen.org/privilege/alarm.set

+0

是的,我做過了。 這些行位於watchface應用程序的tizen-manifest.xml中。 – Gregory

+0

用清單文件中的代碼編輯問題。我沒有得到這樣的錯誤。我猜你錯過了任何步驟。 –

回答

1

您可以嘗試在此目的下使用Alarm API。遵循以下步驟:

  1. 首先創建一個監視應用程序和一個服務應用程序。打包這兩個應用程序和構建。請通過this link來做包裝。
  2. 現在在watchface應用程序中使用下面的代碼片段在特定時間後觸發警報,在您的情況下爲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); 
} 

N.B:不要忘了添加權限的通知。

+0

謝謝!但是** alarm_schedule_after_delay()**返回** ALARM_ERROR_NOT_PERMITTED_APP **,這表示 - 如果app_control不是UI應用程序,則返回ALARM_ERROR_NOT_PERMITTED_APP._([description](https://developer.tizen.org/ko/development/) API-引用/本地的應用程序?重定向=/DEV-引導/ 2.4/org.tizen.native.mobile.apireference/group__CAPI__ALARM__MODULE.html#ga83e440e25f14588b9bf2a6193cf6653c))。如何解決它? – Gregory

+0

請使用您的代碼編輯帖子。 –

相關問題