Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share image with other apps

Here is my problem... I want to share a png image. I have the image in drawable and assets. When I use the sharingIntent it works but not in the way that I want. The file shared appears with numbers and without extension and some apps send the message "unknow file". What can i do??

this is my code:

    Uri uri = Uri.parse("android.resource://com.example.shareimages/" + R.drawable.caja);
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);

    shareIntent.setType("image/png");

    shareIntent.putExtra(Intent.EXTRA_STREAM,  uri);

    startActivity(Intent.createChooser(shareIntent, "send"));

I tried to use instead of drawable files, the files in assets ( with this "file:///android_asset/...) but it didn't work

like image 401
superpichon Avatar asked Dec 19 '12 05:12

superpichon


1 Answers

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

like image 114
Anup Cowkur Avatar answered Nov 01 '22 02:11

Anup Cowkur