0

I would love to share a picture with a text or url. I'm using this code but I am only sharing the image, and changing the order of the "type" makes me share both but only as email / gmail What am I doing wrong? my code is:

edit1

Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
           share.setType("*/*");
           share.putExtra(Intent.EXTRA_STREAM,               Uri.parse("file:///sdcard/Wallpaper/1.jpg"));
           share.putExtra(Intent.EXTRA_TEXT, "helloworld");
           startActivity(Intent.createChooser(share, (getApplicationContext().getString(R.string.condividi))));
Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55
Gapp Aiello
  • 182
  • 1
  • 15
  • In the question you mentioned ACTION_SEND i.e. you want to send single file but in your code you want to send multiple files and providing only single URI. What you wanna do? – Rohan Kandwal Feb 18 '14 at 12:20

3 Answers3

0

Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.

Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.

More info about ACTION_SEND_MULTPLE and handling MIME types:

http://developer.android.com/reference/android/content/Intent.html

Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55
0

If you want to send multiple files then use the following code :-

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Add any subject");
intent.setType("image/*"); /* sharing any type of image. Modify to your need */

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

for(String path : filesToSend /* List of images you want to send */) {
    File file = new File(path);
    Uri uri = Uri.fromFile(file);
    files.add(uri);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); /* adding files to intent */
startActivity(intent);
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • I have to use filesToSend as a variable? – Gapp Aiello Feb 18 '14 at 12:24
  • **filesToSend ** is string array which has paths of all your images like `http://url of image/ab.png`, `http://url of image/abc.png`, `http://url of image/abcd.png`, etc. – Rohan Kandwal Feb 18 '14 at 12:27
  • but the image is already on the phone and the path is predefined by me – Gapp Aiello Feb 18 '14 at 12:34
  • @GappAiello First of all you want to send single file or multiple files? Your question's title and posted code is confusing me. – Rohan Kandwal Feb 18 '14 at 12:37
  • i want to send the image of the path "file :/ / / sdcard/Wallpaper/1.jpg" with a text – Gapp Aiello Feb 18 '14 at 12:39
  • try this in `..EXTRA_STREAM, Uri.fromFile(new File("file :/ / / sdcard/Wallpaper/1.jpg"))` instead of `share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Wallpaper/1.jpg"));` – Rohan Kandwal Feb 18 '14 at 12:45
  • @GappAiello also replace `ACTION_SEND_MULTIPLE` with `ACTION_SEND` in your code (do both suggestions in your code not mine). – Rohan Kandwal Feb 18 '14 at 12:52
  • see this question http://stackoverflow.com/q/6814268/1979347 and http://stackoverflow.com/q/14326313/1979347 and also whatsapp don't allow sharing both image and data at the same time see this answer http://stackoverflow.com/a/15526495/1979347 – Rohan Kandwal Feb 18 '14 at 13:19
  • friend there are applications that do this with whatsapp and facebook – Gapp Aiello Feb 18 '14 at 13:36
0

try this

File DoutFile = new File(path);

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/*");

        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(DoutFile));
        share.putExtra(Intent.EXTRA_TEXT,
                "" + getResources().getString(R.string.app_name));

        startActivity(Intent.createChooser(share, "Share Image"));
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177