Đức Minh
Đức Minh

Reputation: 49

How to share text in Instagram

I need share text to instagram but I can't use android

intent.putExtra(Intent.EXTRA_TEXT,"MY TEXT");

nothing happen.please help me to do this

Upvotes: 2

Views: 10394

Answers (4)

droidev
droidev

Reputation: 7390

Unfortunately Instagram doesn't receives text from intent. it receives only EXTRA_STREAM object. you can share only images of format jpeg, gif, png. Since they are not providing any SDK you cant share in any other way.

Check Instagram developer documentation here they were clearly mentioning that the accepting Intent Parameter as EXTRA_STREAM

This is the code for sharing photo in Instagram

String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;

createInstagramIntent(type, mediaPath);

private void createInstagramIntent(String type, String mediaPath){

    // Create the new Intent using the 'Send' action.
    Intent share = new Intent(Intent.ACTION_SEND);

    // Set the MIME type
    share.setType(type);

    // Create the URI from the media
    File media = new File(mediaPath);
    Uri uri = Uri.fromFile(media);

    // Add the URI to the Intent.
    share.putExtra(Intent.EXTRA_STREAM, uri);

    // Broadcast the Intent.
    startActivity(Intent.createChooser(share, "Share to"));
}

Upvotes: 2

siliconeagle
siliconeagle

Reputation: 7383

Instagram have stopped accepting pre-populated capitions to increase the quality of content in the system. See this post.

http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing

Upvotes: 7

Akshay Bhat 'AB'
Akshay Bhat 'AB'

Reputation: 2700

Here is the intent code to share image and text in Instagram.

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"YOUR TEXT TO SHARE IN INSTAGRAM");
shareIntent.setPackage("com.instagram.android");
return shareIntent;

Upvotes: 1

KOTIOS
KOTIOS

Reputation: 11194

Generic code for sharing text with any social app :

Step1 : Get the package name of app you wanna share :

To get the package name use adb logcat -s ActivityManager this command in windows and run the app like for example you want package name for instagram so run above command and open instagram app you would get the package name in logs Note : the adb command listed above is for windows . For ubntu you can use adb logcat | grep "ActivityManager"

STEP 2 : Once you got the package name of app below is generic code for sharing text .

 try {
                    Intent shareOnAppIntent = new Intent();
                    shareOnAppIntent .setAction(Intent.ACTION_SEND);
                    shareOnAppIntent .putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_body));
                    shareOnAppIntent .setType("text/plain");
                    shareOnAppIntent .setPackage(PACKAGE_NAME_OF_APP);
                    startActivity(shareOnAppIntent );
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(ShareAppActivity.this, "APP is not installed", Toast.LENGTH_LONG).show();
                }

Upvotes: 3

Related Questions