27

Instagram for Android is very limited, from what I have seen so far. My scenario is simple: allow the user to edit a picture and when he clicks on Send:

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

Then with queryIntentActivities() I search to see if Instagram is installed. If it is I send the path of my image to be uploaded:

 share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path to myfile.png"));
 share.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
 share.putExtra(Intent.EXTRA_SUBJECT, "Sample subject");
 share.putExtra(Intent.EXTRA_TEXT, "Sample text");
 share.putExtra(Intent.EXTRA_TITLE, "Sample title");

The result: the image is uploaded using Instagram app (of course if I am logged in), but I can't add a Caption to it. None of the putExtra has any effect. So, is there any way to add a caption as intent parameter ?

And the other question, is it possible to open Instagram app with a certain user name filled in ?

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
Alin
  • 14,809
  • 40
  • 129
  • 218

2 Answers2

8

It looks as if Instagram's Android App ignores EXTRA_TEXT, EXTRA_SUBJECT and EXTRA_TITLE, so it seems that adding a caption while uploading an image is not possible. By the way, you can try different approaches to check if it ignores those extras in every case:

OPTION #1: Changing the MIME type.

You are setting the MIME type to "image/jpeg". Try using "image/" or "/*" to check if their app doesn't ignore those extras.

share.setType("image/*");

or

share.setType("*/*");

OPTION #2:

As you are sending multiple MIME types (image and text), maybe their app is expecting ACTION_SEND_MULTIPLE instead of ACTION_SEND.

Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);

OPTION #3: Use MediaStore.Images.Media.insertImage(ContentResolver cr, String imagePath, String name, String description) function:

Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), "file:///" + path to myfile.png", "Sample title", "Sample description")));
share.setType("image/jpeg");
share.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

OPTION #4: Post your issue in their developer forum, although there are similar questions that remain unsolved:

And don't forget to come back and tell us their answer!

Alejandro Colorado
  • 6,034
  • 2
  • 28
  • 39
  • Since there wasn't any response to this answer: - Setting type to \*/\* sends me straight to the news feed - Looks like are a number of ways to get an image over to the Instagram application, but no way to include a caption. Please correct me if I'm wrong, and please post any solutions to include a caption. – Kent Robin Jun 11 '14 at 08:04
4

It looks like Instagram has updated their app to accept EXTRA_TEXT to add a caption. If the user has an updated version of Instagram (July 1, 2014 version or later) you can post an image and add a caption with the following code:

Intent instagram = new Intent(android.content.Intent.ACTION_SEND);
instagram.setType("image/*");
instagram.putExtra(Intent.EXTRA_STREAM, [URI of photo]);
instagram.putExtra(Intent.EXTRA_TEXT, [Text of caption]);
instagram.setPackage(instagramPackageName);
startActivity(instagram);

Users with older versions will still get the image, but not have the caption be pre populated.

This code is assuming you have already been through the auth flow.

Chriskot
  • 647
  • 4
  • 7
  • Thanks for sharing this, it's great that they finally added this option. – Alin Jul 10 '14 at 09:55
  • 3
    I can confirm they remove the option to set the caption sometime, last week. EXTRA_TEXT disappeared from the documentation: https://instagram.com/developer/mobile-sharing/android-intents/ – Leonel Galán Aug 04 '15 at 15:41
  • Late answer, but might help someone...I just put whatever caption I want to send to Instagram in the clipboard. I have a little popup that instructs the user to long-press Instagram's caption and then simply click 'paste' to insert whatever caption text was generated in my app. – Martin Mar 17 '16 at 17:48