简体   繁体   English

Android Facebook-登录/注销对话框

[英]Android Facebook - Login / Logout Dialog

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. 我已经成功地实现了将Facebook登录到我的Android应用程序中。我面临的问题是,在我注销时,每当我单击注销按钮时,我都想捕获“取消/注销”选项的单击。我要去做吗?下面附有图片,以使插图更清晰。

登出页面

在此处输入图片说明

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 now this post is very old but... 我现在这个帖子很旧,但是...

I had the same problem as you, what I did was: 我和你有同样的问题,我所做的是:
(only sure for facebook sdk v2.0) (仅对于facebook sdk v2.0确定)

1. Go to package com.facebook.widget; 1.转到com.facebook.widget包;

2. Open the file LoginButton.java ; 2.打开文件LoginButton.java

3. Go to line 819 inside the public void onClick(View v) ; 3.转到public void onClick(View v)内部的第819行;
4. See the allert Dialog? 4.见提示对话框? I just comented the code as follows: 我只是将代码写成如下:

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();
                           }
                       });
                       /*.setNegativeButton(cancel, null);*/
                builder.create().show();

And it is done!, no more annoying cancel button on dialog. 做到了!,不再在对话框上烦人的取消按钮。
(You can also remove the whole dialog) (您也可以删除整个对话框)

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: 我遇到了同样的问题并搜索了许多答案,但是它们不起作用,所以我只是在Facebook sdk的LoginButton.java中写了一些新代码,我的第一步是:

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: 第二步:在LoginButton.java中找到811行,您将看到如下代码:

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. 我在facebook sdk中更改了一些代码,它为我工作了,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM