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

北城余情 提交于 2019-11-30 23:18:32

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

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.

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!