Share text and Image together using Facebook SDK in Android

微笑、不失礼 提交于 2020-01-29 05:30:19

问题


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...


回答1:


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"



来源:https://stackoverflow.com/questions/11504129/share-text-and-image-together-using-facebook-sdk-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!