Share images from URL via Twitter app - Android

I am trying to share some texts and images through the Twitter app. Image source is a web address. 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 shared through the Twitter app. I also get a message saying " Image could not be uploaded ." What is the problem with this code?

+7
android uri android-intent twitter android-sharing
source share
1 answer

Suraw, I think you should download a picture before sharing it. You can do it manually , or maybe you can use a library like this . You can find easy documentation in the library repository on how to configure and use it.

Once you have uploaded the image, 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 just want to simulate Image Analysis on the fly, delete it after sharing.

Hope this helps you!

+7
source share

All Articles