使用Android存储访问框架编写数据的文件的最佳方法是什么?

发布于 2025-02-07 13:35:46 字数 844 浏览 2 评论 0原文

我想使用Android存储访问框架编写一个带有数据的文件,但我面临一些问题。在以下代码中,我可以创建一个文件,但文件为空白。

 Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
                       intent.setType("application/vnd.ms-excel");
                       intent.putExtra(Intent.EXTRA_TITLE,DATABASE_NAME+"_"+AppUtils.getCurrentDate()+".xls");
                       startActivityForResult(intent,CREATE_FILE);

如果我使用以下代码,那么我可以从onActivityResult中获取写作访问权限,

  Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                        intent.addCategory(Intent.CATEGORY_OPENABLE);
                        intent.setType("application/vnd.ms-excel");
                        startActivityForResult(intent,WRITE_FILE);

以使我的无用户友好,因为用户必须创建一个文件首先,他们必须再次选择它以编写数据。我希望直接创建文件并将文件写入Android存储访问框架。有什么好方法吗?请帮忙。

I want to write a file with data using Android Storage Access Framework but I am facing some problems. in this below code I can create a file but the file is blank.

 Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
                       intent.setType("application/vnd.ms-excel");
                       intent.putExtra(Intent.EXTRA_TITLE,DATABASE_NAME+"_"+AppUtils.getCurrentDate()+".xls");
                       startActivityForResult(intent,CREATE_FILE);

if I use this below code then I can get writing access to throw the Uri from onActivityResult

  Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                        intent.addCategory(Intent.CATEGORY_OPENABLE);
                        intent.setType("application/vnd.ms-excel");
                        startActivityForResult(intent,WRITE_FILE);

it makes my app-less user-friendly because the users will have to create a file first then they have to select it again for writing data on it. I am expecting something directly to create and write the file into the Android Storage Access Framework. is there any good way to do that. please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文