Android Facebook SDK: Check if the user is logged in or not

后端 未结 10 1483
南旧
南旧 2020-12-04 12:43

I\'m have a feature on my Android app where the user authorizes the app and shares a link.

I also need to give an option for the user to logout of facebook and I nee

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 13:11

    For Facebook Android SDK 4.x you have to use the "AccessToken.getCurrentAccessToken()" as said by @Diljeet but his check didn't work for me, I finally checked it by doing:

    Activity "onCreate":

    facebookAccessToken = AccessToken.getCurrentAccessToken();
    

    To check if the session is still active (I made it in the "onResume" method but do it where you need):

      if(facebookAccessToken != null){
            sessionExpired = facebookAccessToken.isExpired();
      }else{
            sessionExpired = true;
      }
    

    More info in https://developers.facebook.com/docs/facebook-login/android

提交回复
热议问题