Write to a file in Tizen Native Application

2019-09-19 06:42发布

I am trying to log the Heart Rate of the Gear S3 to a simple text file using a Tizen Native Application. The only way I could find yet, is with a Web Application... is it possible with a Native App? And if so, Where do I find the reference?

Thanks a lot

1条回答
2楼-- · 2019-09-19 07:05

The res folder does not allow writing text in a file, It has only Read permission. So you should save it in data folder which has Read and Write permission.

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 is my custom function where i put every UI component in box container

查看更多
登录 后发表回答