Share text and Image together using Facebook SDK in Android

13,961

Hey this code might be helpful,

Bundle parameters = new Bundle();
                parameters.putString("message", category_item_name_desc.getText().toString());
                parameters.putString("picture", categoryItemsModel.getImageUrl());
                parameters.putString("caption", txtDescription_desc.getText().toString());
                facebook.request("/me/feed", parameters, "POST");

You can add text by adding paramater as "caption"

Share:
13,961
Dilip
Author by

Dilip

Computer science Engineer. I love designing and coding Software Applications.Started my career with Java including Android SDK & NDK.Currently working on Android Application Development and have developed mostly application related to E-Commerce,Multimedia,GPS,Database and Web services.

Updated on June 28, 2022

Comments

  • Dilip
    Dilip almost 2 years

    I'm using facebook SDK for share text and image in Android.I have used following code and its working for share text but how to share image together.I'm so confused about this.If any know please suggest me.

    Code:

    public class MainActivity extends Activity {
    
    Facebook facebook = new Facebook("App ID");
    EditText edittext;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edittext = (EditText) findViewById(R.id.revieew);
    
        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
            }
    
            @Override
            public void onFacebookError(FacebookError error) {
            }
    
            @Override
            public void onError(DialogError e) {
            }
    
            @Override
            public void onCancel() {
            }
        });
    }
    
    public void share(View v) {
        //facebook.dialog(this, "feed", new PostDialogListener());
    
        Bundle parameters = new Bundle();
        // parameters.putString("message", category_item_name_desc.getText()
        // .toString());
        // parameters.putString("picture", categoryItemsModel.getImageUrl());
        parameters.putString("caption", edittext.getText().toString());
        try {
            facebook.request("/me/feed", parameters, "POST");
            System.out
                    .println("**********************POST**********************************");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    
        facebook.authorizeCallback(requestCode, resultCode, data);
    }
    

    } And also i don't want to show dialog for share image and text i want to use Edittext and button for that...

  • Dilip
    Dilip almost 12 years
    Thanks for suggest, But this is not working......and also not throwing any error.......
  • user
    user almost 12 years
    there are few changes in facebook SDK i have implemented it so might this be the reason am getting it ... here is the link for facebook SDK changes github.com/johnmph/facebook-android-sdk/commit/…
  • Jeremy C.
    Jeremy C. over 8 years
    Aug 2015:: Facebook SDK has changed since this answer.. The 'picture' and 'caption' edges are no longer existent on the '/me/feed' graph. developers.facebook.com/docs/graph-api/reference/v2.4/user/f‌​eed