Android的Facebook的 - 登录/注销对话框 [英] Android Facebook - Login / Logout Dialog
问题描述
我已经设法成功实施的Facebook登录到我的Android app.The问题,我面对的是,在我的注销,每当我点击注销按钮,我想捕捉的取消/退出选项点击。怎么我去这样做呢?下面是对连接更清晰的插图图像。
由于在图像显示,我怎么去突出显示的红色圆圈捕捉点击?
以下附件是我的codeS的登录/注销活动为well.Thank你:)
查看= inflater.inflate(R.layout.splash,集装箱,FALSE);
LoginButton authButton =(LoginButton)查看
.findViewById(R.id.login_button);
authButton.setFragment(本);
//获取更多的权限
authButton.setPublishPermissions(数组
.asList(publish_actions,read_stream));
authButton.setFragment(getParentFragment());
我得到了同样的问题,一些搜索许多答案,但他们亘古不变的工作,所以我只是写了一些新的codeS里LoginButton.java了Facebook SDK ,我弗里斯特步:
公共接口LogoutListener {
公共无效afterLogin();
}私人LogoutListener mLoginoutListener;公共无效setLogoutListener(LogoutListener loginoutListener){
this.mLoginoutListener = loginoutListener;
}
第二步:找到LoginButton.java 811线,你会看到code就像这样:
私有类LoginClickListener实现OnClickListener { @覆盖
公共无效的onClick(视图v){
上下文的背景下=的getContext();
最后一次会议的openSession = sessionTracker.getOpenSession(); 如果(的openSession!= NULL){
//如果会话当前打开的,就一定意味着我们需要注销
如果(confirmLogout){
//创建一个确认对话框
。字符串注销= getResources()的getString(R.string.com_facebook_loginview_log_out_action);
字符串取消= getResources()的getString(R.string.com_facebook_loginview_cancel_action)。
字符串消息;
如果(用户= NULL和放大器;!&安培;!user.getName()= NULL){
消息=的String.format(getResources()的getString(R.string.com_facebook_loginview_logged_in_as),user.getName());
}其他{
消息= getResources()的getString(R.string.com_facebook_loginview_logged_in_using_facebook)。
}
AlertDialog.Builder建设者=新AlertDialog.Builder(背景);
builder.setMessage(消息)
.setCancelable(真)
.setPositiveButton(注销,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释它){
openSession.closeAndClearTokenInformation(); //这里是我加什么
如果(mLoginoutListener!= NULL){
mLoginoutListener.afterLogin();
}
}
})
.setNegativeButton(取消,NULL);
builder.create()显示()。
}其他{
openSession.closeAndClearTokenInformation();
}
第三步,这是我如何使用:
LoginButton floginButton =(LoginButton)findViewById(R.id.flogin_button);
floginButton.setLogoutListener(新LogoutListener(){
@覆盖
公共无效afterLogin(){
//你想要什么,当用户点击确定按钮。 }
});
我改变了一点点codeS了Facebook SDK,和它的工作对我来说,我希望这可以帮助你。
I've managed to successfully implement Facebook login into my Android app.The issue I'm facing is,on my logout,whenever I click the logout button,I would like to capture the click of "Cancel / Logout" options.How do I go about doing this?Below are images attached for a much clearer illustration.
As shown in the images,how do I go about capturing the clicks in the highlighted red circles? Below attached are my codes for the login/logout activity as well.Thank you :)
View view = inflater.inflate(R.layout.splash, container, false);
LoginButton authButton = (LoginButton) view
.findViewById(R.id.login_button);
authButton.setFragment(this);
// Get more permissions
authButton.setPublishPermissions(Arrays
.asList("publish_actions,read_stream"));
authButton.setFragment(getParentFragment());
I got the same problem and searched some many answers,but they doesnot work,so I just write some new codes in LoginButton.java in facebook sdk,my frist step:
public interface LogoutListener{
public void afterLogin();
}
private LogoutListener mLoginoutListener;
public void setLogoutListener(LogoutListener loginoutListener){
this.mLoginoutListener = loginoutListener;
}
second step:find 811 lines in LoginButton.java and you will see the code just like this:
private class LoginClickListener implements OnClickListener {
@Override
public void onClick(View v) {
Context context = getContext();
final Session openSession = sessionTracker.getOpenSession();
if (openSession != null) {
// If the Session is currently open, it must mean we need to log out
if (confirmLogout) {
// Create a confirmation dialog
String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
String message;
if (user != null && user.getName() != null) {
message = String.format(getResources().getString(R.string.com_facebook_loginview_logged_in_as), user.getName());
} else {
message = getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setCancelable(true)
.setPositiveButton(logout, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
openSession.closeAndClearTokenInformation();
// here is what I added
if(mLoginoutListener != null){
mLoginoutListener.afterLogin();
}
}
})
.setNegativeButton(cancel, null);
builder.create().show();
} else {
openSession.closeAndClearTokenInformation();
}
third step,and this is how I use :
LoginButton floginButton = (LoginButton)findViewById(R.id.flogin_button);
floginButton.setLogoutListener(new LogoutListener() {
@Override
public void afterLogin() {
// do what you want ,when user click the "OK" button.
}
});
I changed a little bit codes in facebook sdk,and it worked for me,I hope this can help you.
这篇关于Android的Facebook的 - 登录/注销对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!