将文件从 apphomepath 复制到代号 one 中的下载文件夹

问题描述 投票:0回答:0

我在 codenameone 应用程序工作。我喜欢将 gpx 文件制作为应用程序并将这些文件复制到我手机上的下载文件夹中。这样我以后就可以使用这些文件。我没有在 stackoverflow 或 codenameone 开发者指南中找到好的解决方案。 gpx 文件是在 webview 中使用 javascript

创建的

我试过了 (a) 使用 javascript 我的代码在桌面上运行良好,但在手机上运行不佳。 (b) 本地代码。我使用了 Environment.getExternalStorageDirectory 但它已被 api 29 弃用。

有人有解决办法吗?最简单的方法是使用 javascript。

我在javascript中的代码是

async function getsaveFile(content, filenm) {
// create a new handle
const opts = {

    types: [
        {
          
            description: "Text file",
            accept: { "text/plain": [".txt"] },
        },
    ],
};


const newHandle = await window.showSaveFilePicker(opts);

// create a FileSystemWritableFileStream to write to
const writableStream = await newHandle.createWritable();
let blob = new Blob([content], { type: 'text/plain' });
// write our file
await writableStream.write(blob);

// close the file and write the contents to disk.
await writableStream.close();

}

android codenameone
© www.soinside.com 2019 - 2024. All rights reserved.