Android: How to share image with text on facebook via intent?

I'd like to share a photo with caption pre-filled from my app via a share intent, on facebook.

Example code

Intent intent = new Intent();

intent.putExtra(Intent.EXTRA_TEXT, "eample");
intent.putExtra(Intent.EXTRA_TITLE, "example");
intent.putExtra(Intent.EXTRA_SUBJECT, "example");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);

Intent openInChooser = new Intent(intent);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);

Here is screen shot what I get

If a set type to image/* then a photo is uploaded without the text prefilled. If a set it to text/plain photo is not display.....


The newest Facebook versions doesn't allow you to share text using intents. You have to use the Facebook SDK to do it - to make that simple, use the Facebook SDK + Android Simple Facebook ( Using the library, your code would be like this (extracted from the Simple Facebook site):

Publish feed

Set OnPublishListener and call for:

  • publish(Feed, OnPublishListener) without dialog.
  • publish(Feed, true, OnPublishListener) with dialog.
Basic properties
  • message - The message of the user
  • name - The name of the link attachment
  • caption - The caption of the link (appears beneath the link name)
  • description - The description of the link (appears beneath the link caption)
  • picture - The URL of a picture attached to this post. The picture must be at least 200px by 200px
  • link - The link attached to this post

Initialize callback listener:

OnPublishListener onPublishListener = new OnPublishListener() {
        public void onComplete(String postId) {
            Log.i(TAG, "Published successfully. The new post id = " + postId);

      * You can override other methods here: 
      * onThinking(), onFail(String reason), onException(Throwable throwable)

Build feed:

Feed feed = new Feed.Builder()
    .setMessage("Clone it out...")
    .setName("Simple Facebook for Android")
    .setCaption("Code less, do the same.")
    .setDescription("The Simple Facebook library project makes the life much easier by coding less code for being able to login, publish feeds and open graph stories, invite friends and more.")

Publish feed without dialog:

mSimpleFacebook.publish(feed, onPublishListener);

Publish feed with dialog:

mSimpleFacebook.publish(feed, true, onPublishListener);

Update on 14 December 2015

according to New Facebook SDK.


It's very Simple. 1. create Provider in Android.manifest.xml

            android:exported="true" />

2. Create Your Share Intent with Data.

ShareHashtag shareHashTag = new ShareHashtag.Builder().setHashtag("#YOUR_HASHTAG").build();
ShareLinkContent shareLinkContent = new ShareLinkContent.Builder()
                .setQuote("Your Description")
                .setContentUrl(Uri.parse("image or logo [if playstore or app store url then no need of this image url]"))

3. Show The Share Dialog,shareLinkContent);

That's It.

Try with this

private void initShareIntent(String type,String _text){
     File filePath = getFileStreamPath("shareimage.jpg");  //optional //internal storage
     Intent shareIntent = new Intent();
     shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
     shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath)));  //optional//use this when you want to send an image
     startActivity(Intent.createChooser(shareIntent, "send"));

As of 2017, facebook doesn't allow sharing of an image + text together, directly from your app.


Facebook will though, scrape a URL for title and image data and will use that in a share post.

As a workaround you could create a single page application* that dynamically loads the text/image you want to share (specified in the URL) and you can facebook-share that URL.


  • Ensure your single page application produces a static page which has its title, open graph meta tags, and images set prior to facebook's page scrape. If these web page tags are changed dynamically through Javascript, facebook will not be able to scrape those values and use them in its share post.
  • Use open graph meta property tags og:image:height and og:image:width to allow facebook to create an image preview within its share post


0) add the latest facebook-sdk library to your build.gradle file

compile group: '', name: 'facebook-android-sdk', version: '4.25.0'

1) In your AndroidManifest.xml, add a meta-data tag within your <application> section:

<application android:label="@string/app_name" ...>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

Add a facebook_app_id string (with your APP ID) to your strings.xml file:

<string name="facebook_app_id">12341234</string>

YOURFBAPPID is your Facebook App ID number found at

2) also add a <provider> tag outside of your <application> tag in AndroidManifest.xml

<provider android:authorities=""

3) Create a ShareLinkContent object using their builder:

ShareLinkContent fbShare = new ShareLinkContent.Builder()

4) Share it from your fragment (or activity, etc.):, fbShare);

Facebook Docs

FB no longer allows you to prefill the sharing message.

In order to circumvent this, you will need to use an SDK to publish via a Graph request. For this you will need the publish_actions permission. Since last month you need to submit your app to a review process to gain access to publish_actions. Which you would fail if your app prefills the sharing texts. Trust me - I've had the Chutzppah to try.

So it looks like we would have to comply.

B.t.w. in iOS you can still prefill the texts using the FB sdk. Who knows for how long.

Without using Facebook sdk we can't share the image and text simultaneously on facebook. To solve this problem I had create a bitmap of image and text, Share that bitmap on facebook and it's working perfectly.

You can download the source code from here (Share image and text on facebook using intent in android)

Here is code:

package com.shareimage;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements 
View.OnClickListener {
EditText et_text;
ImageView iv_image;
TextView tv_share,tv_text;
RelativeLayout rl_main;

protected void onCreate(Bundle savedInstanceState) {



private void init(){
    et_text = (EditText)findViewById(;
    iv_image = (ImageView)findViewById(;
    tv_share = (TextView)findViewById(;
    rl_main = (RelativeLayout)findViewById(;
    tv_text= (TextView) findViewById(;

    File dir = new File("/sdcard/Testing/");
    try {
        if (dir.mkdir()) {
            System.out.println("Directory created");
        } else {
            System.out.println("Directory is not created");
    } catch (Exception e) {


    et_text.addTextChangedListener(new TextWatcher() {
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {


        public void onTextChanged(CharSequence s, int start, int before, int count) {


        public void afterTextChanged(Editable s) {



public void onClick(View v) {

    switch (v.getId()){
            Bitmap bitmap1 = loadBitmapFromView(rl_main, rl_main.getWidth(), rl_main.getHeight());
            String str_screenshot = "/sdcard/Testing/"+"testing" + ".jpg";



public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File("/sdcard/Testing/"+"testing" + ".jpg");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

        Log.e("ImageSave", "Saveimage");
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);

public static Bitmap loadBitmapFromView(View v, int width, int height) {
    Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);

    return b;

public void fn_share(String path) {

    File file = new File("/mnt/" + path);

    Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
    Uri uri = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(intent, "Share Image"));



In this Formula you can share image both Messenger and Instagram( without using any Provider in "AndroidManifest

public void shareMessenger(View v) {
    // showToast("checking");

    File dir = new File(Environment.getExternalStorageDirectory(), "MyFolder");

    File imgFile = new File(dir, "Image.png");

    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imgFile));
    sendIntent.putExtra(Intent.EXTRA_TEXT, "<---MY TEXT--->.");
    try {
        startActivity(Intent.createChooser(sendIntent, "Share images..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(SaveAndShareActivity.this, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();


**Add this two line in onCreate Method **

 StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();

Add these lines to your following code

shareCaptionIntent.putExtra(Intent.EXTRA_TITLE, "my awesome caption in the EXTRA_TITLE field");

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);


   shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name));

   shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); // put your image URI

   PackageManager pm = v.getContext().getPackageManager();

   List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);

     for (final ResolveInfo app : activityList) 
         if (("facebook")) 

           final ActivityInfo activity = app.activityInfo;

           final ComponentName name = new ComponentName(activity.applicationInfo.packageName,;


          shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);




Need Your Help

preg_match(): Compilation failed: invalid range in character class at offset

php regex preg-match

Thank you in advance for you time in helping with this issue..

Error: getaddrinfo ENOTFOUND in nodejs for get call

node.js mongodb backbone.js express restify

I am running a web server on node the code for which is given below