简体   繁体   中英

Sharing failed while sharing Firebase image URI to other apps?

While sharing image URI to other sharing is getting failed. So I want a solution on how to share my app images to other app using bluetooth, whatsapp etc.

Here is my code:

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.."));
}

My suggestion first save image which u want to share then pass uri

Ref : Share Image with Other Apps

Try something Like this

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)

If you want to share it via the assets folder, you'll have to use a ContentProvider. See this answer on how to do so:

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

OR

Add File Provider in Android Manifest

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

See That How to use support FileProvider for sharing content to other apps?

this must be because your firebase storage setting didn't allow to read and write without auth

just go to to storage>rules and change the rules with this

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

this will allow everyone can read your image

Warning reading and writing the storage database also count and you need to pay cost to remain it work after certain limit. check pricing here

例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM