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

后端 未结 3 1329
名媛妹妹
名媛妹妹 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: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.

提交回复
热议问题