在Android中使用Facebook SDK共享文本和图像

时间:2012-07-16 12:16:28

标签: android facebook share facebook-android-sdk

我在Android中使用facebook SDK来共享文本和图像。我使用了以下代码,它用于共享文本,但如何共享图像。我对此很困惑。如果有任何需要请建议我。

代码:

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);
}

} 而且我也不想显示共享图像和文本的对话框,我想使用Edittext和按钮...

1 个答案:

答案 0 :(得分:2)

嘿,这段代码可能会有所帮助,

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");

您可以通过将参数添加为“标题”来添加文字