java - 有没有办法通过 Intent 或其他方式共享 *.json 文件?
问题描述
在我的应用程序中,我需要将 *.json 文件共享给其他应用程序(信使、谷歌磁盘等)。我怎样才能通过 Intent 或其他方式做到这一点?
但是当我尝试通过 Intent 执行此操作时,我遇到了一些问题。
override fun shareBackupData(path: String) {
val uri = Uri.parse(path)
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.type = "*/*"
startActivity(Intent.createChooser(shareIntent, "Choose"))
}
当我运行此代码时,我选择要共享的应用程序,然后我看到 toast “不支持的附件”
解决方案
我认为您可以将该文件用作 ExtrtaStream 以下代码共享图像文件您可以将其更改为您的 json 文件
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");//change it with your file
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));
推荐阅读
- reactjs - 从 localStorage 读取值后,如何以编程方式检查单选按钮
- html - 带有左右元素的电子邮件 HTML 导航,包括徽标、按钮和文本
- flutter - Content-Length 标头出现多次,最多允许出现一次
- javascript - 错误:对象作为 React 子对象无效(找到:带有键 {low, high} 的对象)
- python - re.search 模式和长/复杂字符串不匹配
- c# - 用作泛型参数时调用双“==”运算符
- c# - 如何从 FileSystemWatcher Onchanged 事件添加到队列并根据更改的文件触发不同的操作
- java - 自定义 Java 注释以忽略 CI 服务器上的集成测试
- sql - PL/SQL 瀑布桥图
- android - 从 FragmentContainerView 获取添加的子片段