-1

我在我的应用程序中使用 facebook 登录并且它工作正常,但问题是当我单击登录按钮时,它会显示片刻的空白屏幕,我想使用我自己的 asynctask 而不是 facebook。

黑屏

这是我的代码。

ublic class SDLoginActivity extends Activity {

private static final String TAG = SDLoginActivity.class.getSimpleName();
private ImageButton imgbtnFacebookLogin;
private TextView tvUserDetails;
private int counter = 0;

private Session.StatusCallback statusCallback = new SessionStatusCallback();

// ---------------------------------------------------------------------
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Utilities.showToast(SDLoginActivity.this, "Data == " + data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

// ---------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Logger.logger("inside " + TAG);
    setContentView(R.layout.login_layout);
    imgbtnFacebookLogin = (ImageButton) findViewById(R.id.btn_fb_login);
    tvUserDetails = (TextView) findViewById(R.id.tv_user_details);
    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }

    imgbtnFacebookLogin.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            tvUserDetails.setText("");
            onClickLogin();


        }
    });

    // updateView(session);

}

// ---------------------------------------------------------------------

private class SessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(Session session, SessionState state, Exception exception) {

        if (session.isOpened()) {
            updateView(session);
        }

    }
}

// ---------------------------------------------------------------------
@Override
public void onStart() {
    super.onStart();
    Session.getActiveSession().addCallback(statusCallback);
}

// ---------------------------------------------------------------------
@Override
public void onStop() {
    super.onStop();
    Session.getActiveSession().removeCallback(statusCallback);
}

// ---------------------------------------------------------------------
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Session session = Session.getActiveSession();
    Session.saveSession(session, outState);
}

// ---------------------------------------------------------------------
private void updateView(Session session) {
    Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (user != null) {
                Logger.logger(TAG, "======================User Data===================" + user.toString());
                Logger.logger(TAG, "strFbName=======" + user.getName());
                Logger.logger(TAG, "strProfileUrl=======" + "https://graph.facebook.com/" + user.getId() + "/picture?type=large");
                Logger.logger(TAG, "USER_GENDER=======" + user.getProperty("gender").toString());
                Logger.logger(TAG, "strFbId=======" + user.getId());
                Logger.logger(TAG, "strFbName=======" + user.getName());
                Logger.logger(TAG, "strFbUId=======" + user.getId());
                Logger.logger(TAG, "strFbLastName=======" + user.getLastName());
                Logger.logger(TAG, "==================================================");
                counter++;
                Utilities.showToast(SDLoginActivity.this, "OnCompleted called " + counter);
                tvUserDetails.setText(user.getName());

                Utilities.startNewActivity(SDLoginActivity.this, new Intent(SDLoginActivity.this, ShareOnFbActivity.class));
            }
        }
    });
}

// ---------------------------------------------------------------------
private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {

        openMyActiveSession(this, true, statusCallback, Arrays.asList("email", "status_update"));
    } else {
        Session.openActiveSession(this, true, statusCallback);
    }

}

// ---------------------------------------------------------------------
private static Session openMyActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback, List<String> permissions) {
    OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions).setCallback(callback);
    Session session = new Builder(activity).build();
    if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
        Session.setActiveSession(session);
        session.openForRead(openRequest);
        return session;
    }
    return null;
}

}
4

1 回答 1

1

您可以在 AndroidManifest.xml 中将主题设置为不显示 Facbook Login Activity,如下所示

<activity android:name="com.facebook.LoginActivity" 
          android:theme="@android:style/Theme.NoDisplay" />
于 2013-08-10T08:17:54.793 回答