How my app can know when user logout from its Android native Facebook app?

后端 未结 3 1309
名媛妹妹
名媛妹妹 2021-01-06 11:53

How my app can know when user logout from its native Facebook app ?

I am using below code for Logging out from Facebook in my app. And it is working fine.

         


        
相关标签:
3条回答
  • 2021-01-06 12:28

    Hmmmm... It may be get tricky. I guess the isSessionValid is offline checking from the FB API.

    From your situation, it looks like you still need to have a single call to the FB to check the session is really valid or not. So my suggestion based on your situation is to make simple FB API call such as /me just to check the validity of the session.

    If session is valid, then you manually call the logout API, otherwise, you know that the FB session is either expired/logged out.

    Hope helps :)

    0 讨论(0)
  • 2021-01-06 12:40

    Try to check if there's a Facebook account in the system.

    AccountManager accountManager = AccountManager.get(context);
    Account[] facebookAccounts = accountManager.getAccountsByType("com.facebook.auth.login");
    if (facebookAccounts.length > 0) {
        facebook.logout(getApplicationContext());
        ...
    }
    

    Yes, the code contains hard-coded account type, which is slightly unreliable due to possible changes in the native app, though the probability of such changes is very small.

    And don't forget to add a GET_ACCOUNTS permission to the Manifest.

    0 讨论(0)
  • 2021-01-06 12:45

    on destroy you clear the session and token information so that if you logout from your native application .. it will clear its credentials

    use this

      @Override 
      protected void onDestroy() {
    
       // TODO Auto-generated method stub
      super.onDestroy();
     Session session = Session.getActiveSession();
     session.closeAndClearTokenInformation();
    
    
      }
    

    OR

       public void logoutFromFacebook() {
       mAsyncRunner.logout(this, new RequestListener() {
        @Override
        public void onComplete(String response, Object state) {
            Log.d("Logout from Facebook", response);
            if (Boolean.parseBoolean(response) == true) {
                // User successfully Logged out
            }
        }
    
        @Override
        public void onIOException(IOException e, Object state) {
        }
    
        @Override
        public void onFileNotFoundException(FileNotFoundException e,
                Object state) {
        }
    
        @Override
        public void onMalformedURLException(MalformedURLException e,
                Object state) {
        }
    
        @Override
        public void onFacebookError(FacebookError e, Object state) {
        }
    });
    }
    

    try this it works for me .. so it will also resolve your issue also

    0 讨论(0)
提交回复
热议问题