如果我使用ACTION_SEND的Intent并输入“text / plain”并且EXTRA_TEXT Facebook不预先填充任何内容。这是我已经看到的东西。每个人都说,使用Facebook SDK,但我不希望我的应用程序自动发布任何内容,也不希望我的应用程序处理登录令牌。我只想要使用预定义的文本,链接和图像打开Write Post Facebook屏幕。就像我从Gallery应用程序共享图像一样。有可能吗?
答案 0 :(得分:2)
好的,通过Intent无法做到这一点。显示文本,图像+链接并让用户在发布之前编写内容的唯一解决方案是使用丑陋的Feed对话框(或使用EditText创建自定义活动,用户可以在其中编写内容)。
以下是有效的代码:
public class FacebookPostActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_post);
Session.openActiveSession(this, false, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if(session.isOpened()){
publishFeedDialog();
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params)
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if(error == null){
final String postId = values.getString("post_id");
if(postId != null){
Toast.makeText(FacebookPostActivity.this, "Posted story, id: " + postId, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}
}else if(error instanceof FacebookOperationCanceledException){
// User clicked the "x" button
Toast.makeText(FacebookPostActivity.this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}else{
// Generic, ex: network error
Toast.makeText(FacebookPostActivity.this, "Error posting story", Toast.LENGTH_SHORT).show();
}
}
}).build();
feedDialog.show();
}
}