Android的ACTION_CREATE_DOCUMENT,是否可以预填文件名?

huangapple 未分类评论43阅读模式
英文:

Android ACTION_CREATE_DOCUMENT is it possible to prefill filename?

问题

在 Android 应用中,我想要将一些数据导出到一个文件中。我使用 Intent.ACTION_CREATE_DOCUMENT,该选项允许用户选择保存位置。是否有可能预填文件名,例如 "data.txt"?如果我使用 intent.putExtra(Intent.EXTRA_TITLE, "data.txt"),这个操作会被简单地忽略。

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, "data.txt"); // 这个被忽略了
startActivityForResult(intent, MY_CREATE_DOCUMENT_REQUEST_CODE);

我不想创建自定义对话框,因为使用 ACTION_CREATE_DOCUMENT 允许我在没有任何权限的情况下将文件写入存储(因为用户正在选择文件)。

英文:

In android app I want to export some data to a file. I use Intent.ACTION_CREATE_DOCUMENT which lets user choose where to save it. Is it possible to prefill the filename, e.g. "data.txt"? If I use intent.putExtra(Intent.EXTRA_TITLE, "data.txt") it is simply ignored.

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, "data.txt"); // this is ignored
startActivityForResult(intent, MY_CREATE_DOCUMENT_REQUEST_CODE);

I don't want to make custom dialog because using ACTION_CREATE_DOCUMENT allows me to write file to storage without any permissions (because user is choosing file).

huangapple
  • 本文由 发表于 2020年7月26日 21:25:33
  • 转载请务必保留本文链接:https://java.coder-hub.com/63100753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定