首页 > 解决方案 > 分享失败请在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>

我不知道为什么它不共享文件。任何帮助,将不胜感激。谢谢。

标签: android-sharing

解决方案


推荐阅读