与其他应用共享Firebase图像URI时共享失败吗?

时间:2018-08-26 07:09:50

标签: java android android-studio

与其他共享共享图像URI时失败。所以我想要一个解决方案,如何使用蓝牙,whatsapp等与其他应用共享我的应用图像。

这是我的代码:

ArrayList <Uri> imageUri = new ArrayList<>();

for (int i = 0; i < urimodel.size(); i++) {
 Uri model_uri = urimodel.get(i); //getting uri from here

 imageUri.add(model_uri);

 Intent shareIntent = new Intent();
 shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
 shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUri);
 shareIntent.setType("image/*");
 context.startActivity(Intent.createChooser(shareIntent, "Share images to.."));
}

2 个答案:

答案 0 :(得分:2)

我的建议是先保存要共享的图像,然后通过uri

Ref:Share Image with Other Apps

尝试类似的东西

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

// For a file in shared storage.  For data in private storage, use a ContentProvider.
Uri uri = Uri.fromFile(getFileStreamPath(pathToImage));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent)

如果要通过资产文件夹共享它,则必须使用ContentProvider。有关如何操作,请参见以下答案:

https://stackoverflow.com/a/7177103/1369222

  

OR

在Android清单中添加文件提供程序

<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">

<meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/file_provider_paths"/>

  

file_provider_paths.xml

<paths>
    <cache-path name="cache" path="/" />
    <files-path name=”files” path=”/” />
</paths>

看到How to use support FileProvider for sharing content to other apps?

答案 1 :(得分:1)

这一定是因为您的Firebase存储设置不允许在没有auth的情况下进行读写

只需转到storage>规则并以此更改规则

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read;
      allow write: if request.auth != null;
    }
  }
}

这将使每个人都可以阅读您的图像

警告读写存储数据库也很重要,您需要支付一定的费用才能在一定限制后保持其正常工作。检查价格here

example