写入Tizen本机应用程序中的文件 [英] Write to a file in Tizen Native Application

查看:190
本文介绍了写入Tizen本机应用程序中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

非常感谢

推荐答案

res 文件夹不允许在文件中写入文本,它仅具有读取"权限.因此,您应该将其保存在具有读写权限的 data 文件夹中.

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 是我的自定义函数,我在其中将每个UI组件都放在盒子容器中

object_pack is my custom function where i put every UI component in box container

这篇关于写入Tizen本机应用程序中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆