6

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

Nikhil
  • 16,194
  • 20
  • 64
  • 81
superpichon
  • 92
  • 1
  • 8

1 Answers1

5

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

Community
  • 1
  • 1
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • hummm the problem is in the path: 12-18 23:47:45.554: E/AndroidRuntime(26896): FATAL EXCEPTION: main 12-18 23:47:45.554: E/AndroidRuntime(26896): java.lang.IllegalArgumentException: File android.resource://com.example.shareimages/2130837505 contains a path separator what path should use? – superpichon Dec 19 '12 at 06:06
  • you are sharing from internal storage. For internal storage, you'll have to use Content Provider. I have mentioned this in the answer. – Anup Cowkur Dec 19 '12 at 06:14
  • amm sorry thats true...thanks for the help and patience :) ill try the Content Provider – superpichon Dec 19 '12 at 06:16