7

I'm trying to share some text and image via the Twitter app. The image source is a web url. Below is my code:

sharingIntent = new Intent(android.content.Intent.ACTION_SEND);    
sharingIntent.setType("*/*");    
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url+"");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("http://example.com/images/thumbs/file_name.jpg"));

But only the text is getting shared via the Twitter app. I also get a message saying "Image could not be loaded". What is the problem with this code?

Sourav
  • 1,214
  • 14
  • 24

1 Answers1

7

Sourav, I think you must download the picture before sharing it. You can do it manually, or maybe you could use a library like this. You can find inside the library's repository easy documentation about how to set up and use it.

After you have downloaded the picture you can follow this method:

private Intent shareIntent(String bookmark_url, String imagePath){
    sharingIntent = new Intent(android.content.Intent.ACTION_SEND);    
    sharingIntent.setType("*/*");    
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I am reading this publication, check it out here: "+bookmark_url);
    sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
    return sharingIntent;
}

If you simply want to simulate "Parsing image on the fly", delete it after sharing.

Hope this helps you!

Community
  • 1
  • 1
  • I have some constraints in terms of storage on the SD card....can u confirm that sharing the image directly from the URL is not possible in Twitter? – Sourav Jul 01 '14 at 13:17
  • I have seen that happening on other platforms like iOS – Sourav Jul 01 '14 at 13:25
  • @Sourav I cannot confirm that is not possible to share the image directly from the URL but I am pretty sure due to two reasons: 1º your error is quite clear: "Image could not be loaded", 2º I have worked with Twitter API for PHP and I had to download pictures before send a tweet with them because if I didn't do that I obtained text tweets without pictures like you. –  Jul 01 '14 at 13:36