在 Android 中共享失败

问题描述

我正在尝试使用 Intent 共享文件,但是当我在所选应用中单击要共享的联系人时,它会提示共享失败,请重试。它会在其他应用中出现类似的错误

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + share_list.getId();
        File file = new File(path);
        Uri uri = FileProvider.getUriForFile(activity
        activity.getPackageName() + ".provider",file);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("video/*");
        intent.putExtra(Intent.EXTRA_STREAM,uri);
        startActivity(Intent.createChooser(intent,"share using"));

提供者是

<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>

file_path 是

<?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>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)