在 Tizen 本机应用程序中写入文件

Write to a file in Tizen Native Application

我正在尝试使用 Tizen 本机应用程序将 Gear S3 的心率记录到一个简单的文本文件中。我能找到的唯一方法是使用 Web 应用程序……是否可以使用本机应用程序?如果是这样,我在哪里可以找到参考资料?

非常感谢

res文件夹不允许在文件中写入文本,它只有读取权限。所以你应该把它保存在有读写权限的data文件夹中。

char* get_write_filepath(char *filename)
{

    char write_filepath[1000] = {0,};
    char *resource_path = app_get_data_path(); // get the application data directory path
    if(resource_path)
    {           
        snprintf(write_filepath,1000,"%s%s",resource_path,filename);            
        free(resource_path);
    }

    return write_filepath;
}

static char* write_file(const char* filepath, const char* buf)
{

    FILE *fp;
    fp = fopen(filepath,"w");
    fputs(buf,fp);
    fclose(fp);
}

static void btn_write_cb(void *data, Evas_Object *obj, void *event_info)
{

    appdata_s *ad = data;

    char* buf = elm_entry_entry_get(ad->entry);
    char *filepath;
    filepath=get_write_filepath("text.txt"); // "text.txt" is file name
    write_file(filepath,buf);
}

Evas_Object *write_btn = elm_button_add(ad->conform);
elm_object_text_set(write_btn,"Write");
evas_object_smart_callback_add(write_btn,"clicked",btn_write_cb,ad);
object_pack(box,btn,0.0,1.0,-1.0,1.0);

ad->entry = elm_entry_add(ad->conform);
elm_entry_scrollable_set(ad->entry,EINA_TRUE);
elm_object_part_text_set(ad->entry,"elm.guide","Write Text Here");
object_pack(box,ad->entry,1,1,-1,-1);

object_pack 是我的自定义函数,我将每个 UI 组件放入 box container