Question: How to post images selected from gallery to Facebook wall from my android app?


How to post images selected from gallery to Facebook wall from my android app?

Answers 1
Added at 2016-12-27 13:12

I am trying to post image and text to my facebook wall from my own android app. I need to select the image from mobile gallery, but its not working. i am not getting what is the issue in this code. Can anyone please help me??

public class PostFacebook extends Activity{
private Facebook mFacebook;
private CheckBox mFacebookCb;
private ProgressDialog mProgress;
private static final int SELECT_PICTURE = 100;
byte[] inputData;
Uri selectedImageUri;
String imgString;
ImageView image;
private Handler mRunOnUi = new Handler();

private static final String APP_ID = "7************";

protected void onCreate(Bundle savedInstanceState) {


    final EditText reviewEdit = (EditText) findViewById(;
    image = (ImageView) findViewById(;
    mFacebookCb               = (CheckBox) findViewById(;

    mProgress   = new ProgressDialog(this);

    mFacebook   = new Facebook(APP_ID);

    SessionStore.restore(mFacebook, this);

    if (mFacebook.isSessionValid()) {

        String name = SessionStore.getName(this);
        name        = (name.equals("")) ? "Unknown" : name;

        mFacebookCb.setText("  Facebook  (" + name + ")");

    ((Button) findViewById( OnClickListener() {
        public void onClick(View v) {
            String review = reviewEdit.getText().toString();
            try {
                InputStream iStream = getContentResolver().openInputStream(selectedImageUri);
                inputData = GetImage.getBytes(iStream);
                imgString = Base64.encodeToString(inputData, Base64.DEFAULT);
                Log.v("image_check", imgString);
                Toast.makeText(PostFacebook.this, imgString, Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
            if (review.equals("")) 

            if (mFacebookCb.isChecked()) postToFacebook(review, imgString);
    image.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             Intent intent = new Intent();
             startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);

private void postToFacebook(String review, String image) {  
    mProgress.setMessage("Posting ...");;

    AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);

    Bundle params = new Bundle();
    params.putString("message", review);
    params.putString("picture", image);
    params.putString("name", "Hira Ghaffar");
    params.putString("caption", "");
    params.putString("description", "Innovent is an android app developed by iFish Technologies");
    mAsyncFbRunner.request("me/feed", params, "POST", new WallPostListener());

private final class WallPostListener extends BaseRequestListener {
    public void onComplete(final String response) { Runnable() {
            public void run() {

                Toast.makeText(PostFacebook.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                 selectedImageUri = data.getData();
                if (null != selectedImageUri) { 

Answers to

How to post images selected from gallery to Facebook wall from my android app?

nr: #1 dodano: 2016-12-27 13:12

Here, The complete example of share image on facebook wall.

Source Show
◀ Wstecz