且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查用户是否使用 FB SDK 4.0 for Android 登录?

更新时间:2023-12-04 07:58:04

我明白了!

首先,请确保您已初始化您的 FB SDK.其次,添加以下内容:

First, make sure you have initialized your FB SDK. Second, add the following:

accessTokenTracker = new AccessTokenTracker() {
        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) {
            updateWithToken(newAccessToken);
        }
    };

当当前访问令牌发生更改时将调用此方法.意思是,这只会在用户已经登录的情况下对您有所帮助.

This will be called when there's a change on the Current Access Tokes. Meaning, this will only help you if the user is already logged in.

接下来,我们将其添加到我们的 onCreate() 方法中:

Next, we add this to our onCreate() method:

updateWithToken(AccessToken.getCurrentAccessToken());

当然还有我们的updateWithToken()方法:

private void updateWithToken(AccessToken currentAccessToken) {

    if (currentAccessToken != null) {
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, GeekTrivia.class);
                startActivity(i);

                finish();
            }
        }, SPLASH_TIME_OUT);
    } else {
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, Login.class);
                startActivity(i);

                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}

对我来说就是这样!=]

That did it for me! =]