Write to a file in Tizen Native Application

假如想象 提交于 2019-12-25 16:42:44

问题


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:


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



来源:https://stackoverflow.com/questions/41709004/write-to-a-file-in-tizen-native-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!