如果我使用带有 ACTION_SEND 的 Intent 并键入“text/plain”并且 EXTRA_TEXT Facebook 不会预填充任何内容。这是我已经看到的。每个人都说,使用 Facebook SDK,但我不希望我的应用程序自动发布任何内容,也不想处理来自我的应用程序的登录令牌。我只希望用预定义的文本、链接和图像打开 Write Post Facebook 屏幕。就像我从 Gallery 应用程序共享图像一样。可能吗?
问问题
1657 次
1 回答
2
好的,不可能通过 Intent 做到这一点。显示文本、图像+链接并让用户在发布之前写一些东西的唯一解决方案是使用丑陋的提要对话框(或使用 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();
}
}
于 2013-03-14T15:21:42.720 回答