android-sharing - 分享失败请在android studio中重试
问题描述
我正在尝试共享文件,但是当您从选定的应用程序中选择一个联系人时,它会显示 toast 共享失败,请重试。我环顾四周,找到了一些解决方案,但都没有奏效。
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + vs.getId();
Log.e("TAG", "the path is " + path);
Uri uri = FileProvider.getUriForFile(Objects.requireNonNull(activity.getApplicationContext()),
BuildConfig.APPLICATION_ID + ".provider", new File(path));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
activity.startActivity(Intent.createChooser(intent, "share"));
文件的路径是/storage/emulated/0/126303
. 提供者是
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path" />
</provider>
文件路径是
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
我不知道为什么它不共享文件。任何帮助,将不胜感激。谢谢。
解决方案
推荐阅读
- css - 有没有办法使用 CSS 创建这个布局?
- python - 在标准输入上提供文本时如何使用运行而不是通信?
- netty - HTTP 到 HTTPS 代理 CONNECT 处理 - 将代码从 Netty 移植到 Armeria
- apache - 用斜杠替换下划线并删除 .htaccess 中的“.php”
- sql - 从 Access 中的父表单中过滤子表单值
- javascript - Bootstrap 4 按钮如何在不引用 CSS 类的情况下更改移动视图中的状态?
- android - FirebaseMessaging 生成相同的令牌
- javascript - 按行长排序导入 - eslint
- javascript - 无法打开从 System.IO.Compression 命名空间创建的 zip 文件
- android - 非硬编码路径在 picasso android studio 上不起作用