共享文件在android studio中不起作用

问题描述

我正在尝试将文件共享到其他应用程序,但是一旦您选择某个联系人进行共享,就会提示共享失败,请重试。我环顾四周并尝试了一些解决方案,但到目前为止都没有奏效。

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>

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 (将#修改为@)