0

i'm trying to send some images available in asset folder using Intent but it providing error says shared failed try again later please provide me some suggestion.

Here is what i'm doing

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///android_asset/1.jpg"));
startActivity(Intent.createChooser(share, "Share Image!"));

i also trying by using like this

 Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.example.whatsappshare/asset/1.jpg"));
startActivity(Intent.createChooser(share, "Share Image!"));

Both the ways providing same result.

Androidcuckoo
  • 121
  • 2
  • 18

3 Answers3

2

Once you created bitmap as I said earlier, use following snippet to send it as attachment.

String path = Images.Media.insertImage(getContentResolver(), your_bitmap, "title", null);
Uri screenshotUri = Uri.parse(path);

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");

startActivity(Intent.createChooser(emailIntent, "Send email using"));
Pankaj Deshpande
  • 502
  • 2
  • 5
  • 15
0

Assets directory is private to your app and is not available to other apps. So sharing directly from assets is not possible. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file. Have a look here.

Community
  • 1
  • 1
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • if we share all the images in the sdcard is not a good practice know,user want to only share image not to store image – Androidcuckoo Jun 27 '14 at 06:14
  • @Androidcuckoo I am not telling you to share all the images just make a temporary file in the Pictures directory with image from your assets directory and share that file. Always override that file. I am doing this when I upload a photo to my server. If you have any good solution I would like to see it – Illegal Argument Jun 27 '14 at 06:19
  • Sounds good,let me try it out this first and if i found any other better solution surely i will let you know. – Androidcuckoo Jun 27 '14 at 06:26
0

You can't share the file directly, but should be using a content provider to share it.

To avoid writing your own content provider, see cwac-provider

CWAC-Provider: Helping to Make Content Providers Sane

This project offers a StreamProvider, based on Google's FileProvider. Like FileProvider, StreamProvider is designed to serve up files, for reading and writing, through the ContentProvider interface (content:// Uri values). StreamProvider offers:

  • Serving files from assets and raw resources
  • Serving files from getExternalFilesDir() and getExternalCacheDir()
Community
  • 1
  • 1
zmarties
  • 4,809
  • 22
  • 39