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

时间:2019-09-02 12:39:26

标签: tizen tizen-wearable-sdk tizen-native-app tizen-emulator tizen-studio

我正在关注以下示例:https://stackoverflow.com/a/41713258/2330482

但是,重新启动应用程序后无法读取该文件,因此我已经在设备管理器中签入-该文件夹未出现在/opt/usr/home/owner/apps_rw/org.example.basicui/data/中。我cd进入了.basicui目录,ls - l给出了

sh-3.2$ cd apps_rw                                                             
sh-3.2$ cd org.example.basicui
sh-3.2$ ls -l
ls: cannot access cache: Permission denied
ls: cannot access data: Permission denied
total 8
lrwxrwxrwx 1 app_fw app_fw   60 Sep  2 21:31 author-signature.xml -> /opt/usr/globalapps/org.example.basicui/author-signature.xml
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 bin -> /opt/usr/globalapps/org.example.basicui/bin
d????????? ? ?      ?         ?            ? cache
d????????? ? ?      ?         ?            ? data
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 lib -> /opt/usr/globalapps/org.example.basicui/lib
lrwxrwxrwx 1 app_fw app_fw   43 Sep  2 21:31 res -> /opt/usr/globalapps/org.example.basicui/res
drwxr-xr-x 3 owner  users  4096 Sep  2 21:31 shared
lrwxrwxrwx 1 app_fw app_fw   58 Sep  2 21:31 tizen-manifest.xml -> /opt/usr/globalapps/org.example.basicui/tizen-manifest.xml
sh-3.2$ whoami
owner

我的代码如下:

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);

    dlog_print(DLOG_DEBUG, "AAAMYTAG", "written");

}


void saveExampleFile() {
    dlog_print(DLOG_DEBUG, "AAAMYTAG", "save example file");

            char *filepath;
            filepath=get_write_filepath("d.txt");
            write_file(filepath,"TEST");
}

static void //B Button
    btn_go_cb(void *data, Evas_Object *obj, void *event_info)
    {
        dlog_print(DLOG_INFO, "AAAMYTAG", "GO successful.");

        saveExampleFile();
}

我要去哪里错了? data文件夹不应该是永久性的吗?这可以是模拟器错误吗?

2 个答案:

答案 0 :(得分:0)

您是否在config.xml中设置了权限? 认为您需要: tizen:privilege name =“ http://tizen.org/privilege/filesystem.read” tizen:privilege name =“ http://tizen.org/privilege/filesystem.write”

答案 1 :(得分:0)

问题出在Run configurations(在“运行播放”按钮旁边)->“启用更新模式”。

这将使数据持久存在,并且默认情况下被禁用。让它沉入。而不是通过启动来保留数据,而只是在想要删除已安装的应用程序时将其卸载,而三星将其保留下来默认设置为删除数据,并选择保留数据。这是迄今为止最荒谬的操作系统。我永远也无法理解其背后的意图,以及必须使用C和C ++而不是适当的高级语言。难怪没有Tizen应用。