简体   繁体   English

Tizen Wearable Web Widget App 中的文件管理 Tizen SDK 2.3.1 的数据路径

[英]File Management in Tizen Wearable Web Widget App's Data Path for Tizen SDK 2.3.1

I am working on a hybrid tizen app(web + native service) for Samsung Gear Fit2 Pro.我正在为 Samsung Gear Fit2 Pro 开发一个混合 tizen 应用程序(网络 + 本地服务)。 I want to create/setup a config from web ui app and save it into data path of the app so that the native service can load the config and use it.我想从 web ui 应用程序创建/设置一个配置并将其保存到应用程序的数据路径中,以便本机服务可以加载配置并使用它。
I am trying to create a config.txt file from tizen web app at /opt/usr/apps/pkg-id/data .我正在尝试从/opt/usr/apps/pkg-id/data的 tizen web 应用程序创建一个config.txt文件。 I've tried using filesystem API of tizen with proper privileges but it always shows those API functions are undefined.我尝试过使用具有适当权限的 tizen 文件系统 API ,但它总是显示那些 API 函数未定义。 However, if I use resolve then file creation works only for some directories like documents .但是,如果我使用 resolve 那么文件创建仅适用于某些目录,例如documents But I want to create a file if not exists in my app's data folder ie /opt/usr/apps/pkg-id/data or modify it if already exists.但是如果我的应用程序的数据文件夹中不存在,我想创建一个文件,即/opt/usr/apps/pkg-id/data或者如果已经存在则修改它。 Relevant portion of my code that tries to write to a file in data folder is shown below.我的代码中尝试写入数据文件夹中文件的相关部分如下所示。
Is there any way to do that?有没有办法做到这一点? Or am I doing something wrong while using the file-system api?或者我在使用文件系统 api 时做错了什么?

function app_get_datapath() {
    return "/opt/usr/apps/"+tizen.application.getCurrentApplication().appInfo.packageId+"/data/";
}

var fileHandleWrite = tizen.filesystem.openFile(app_get_datapath()+'config.txt', 'w');
fileHandleWrite.writeString(tizen.systeminfo.getCapability('http://tizen.org/system/tizenid'));
fileHandleWrite.close();

Here are the list of privileges:以下是特权列表:
在此处输入图像描述

I've tried using filesystem API of tizen with proper privileges but it always shows those API functions are undefined.我尝试过使用具有适当权限的 tizen 文件系统 API ,但它总是显示那些 API 函数未定义。

Samsung Gear Fit2 Pro does not support all new APIs. Samsung Gear Fit2 Pro 不支持所有新的 API。 Probably you should refer to Tizen 3.0 API , but the API you use in code snippet is supported since Tizen 5.0可能您应该参考Tizen 3.0 API ,但自 Tizen 5.0 起支持您在代码片段中使用的 API

My second comment is that you should not use paths built 'by hand' via string concatenation as you do in app_get_datapath().我的第二条评论是,您不应像在 app_get_datapath() 中那样使用通过字符串连接“手动”构建的路径。 It is highly non-portable solution, which can NOT work on some devices.它是高度非便携的解决方案,无法在某些设备上运行。 Instead I would suggest using built-in virtual root for getting your application private storage - wgt-private , which will automatically return valid path on a device (no matter what the device is).相反,我建议使用内置的虚拟根来获取您的应用程序私有存储 - wgt-private ,它将自动返回设备上的有效路径(无论设备是什么)。

Example (using only 3.0 API, for 5.0 it would be much easier):示例(仅使用 3.0 API,对于 5.0 会容易得多):

(function createConfig() {
    function writeConfig(file) {
        file.openStream('w', function (stream) {
            stream.write(tizen.systeminfo.getCapability('http://tizen.org/system/tizenid'));
            stream.close();
            console.log('All done!!')
        })
    }

    tizen.filesystem.resolve("wgt-private/config.txt", function (file) {
        console.log('Config file exists - overwrite');
        writeConfig(file);
    }, function (e) {
        console.log('Config file does not exist - create');
        tizen.filesystem.resolve("wgt-private", function (dir) {
            var file = dir.createFile("config.txt");
            console.log("Created file")
            writeConfig(file);
        });
});
})()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM