UiLifecycleHelper 是管理您对 facebook api 请求的生命周期的类。它将通过回调为您提供查询或请求的更新或响应。下面是一个带有回调的 facebook 登录的示例实现。 For detailed instruction follow this link.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
//when login
} else if (state.isClosed()) {
//do when no connection or logout
}
}
};
在我上面发布的问题中,我想使用 facebook 的 SHARE 方法。这是我的解决方案:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "SAMPLE POST");
params.putString("caption","SAMPLE CAPTION");
params.putString("description", _sub.getDefinition());
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(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
// Toast.makeText(getActivity(),"Posted story, id: "+postId,Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
Button temp = new Button(getActivity());
temp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
publishFeedDialog();
}
});
有关如何在 facebook 中分享的更详细说明,follow this link。
***注意:请投票给我以做出积极的贡献