public static Account getAccount(final AccountManager manager,
            final Activity activity) throws IOException, AccountsException {
        final boolean loggable = Log.isLoggable(TAG, DEBUG);
        if (loggable) {
            Log.d(TAG, "Getting account");
        }

        if (activity == null) {
            throw new IllegalArgumentException("Activity cannot be null");
        }

        if (activity.isFinishing()) {
            throw new OperationCanceledException();
        }

        Account[] accounts;
        try {
            if (!hasAuthenticator(manager)) {
                throw new AuthenticatorConflictException();
            }

            while ((accounts = getAccounts(manager)).length == 0) {
                if (loggable) {
                    Log.d(TAG, "No GitHub accounts for activity=" + activity);
                }

                Bundle result = manager.addAccount(ACCOUNT_TYPE, null, null,
                        null, activity, null, null).getResult();

                if (loggable) {
                    Log.d(TAG,
                            "Added account "
                                    + result.getString(KEY_ACCOUNT_NAME));
                }
            }
        } catch (OperationCanceledException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            activity.finish();
            throw e;
        } catch (AccountsException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            throw e;
        } catch (AuthenticatorConflictException e) {
            activity.runOnUiThread(() -> showConflictMessage(activity));
            throw e;
        } catch (IOException e) {
            Log.d(TAG, "Excepting retrieving account", e);
            throw e;
        }

        if (loggable) {
            Log.d(TAG, "Returning account " + accounts[0].name);
        }

        return accounts[0];
    }
Get account used for authentication

@param manager
@param activity
@return account
@throws IOException
@throws AccountsException
app/src/main/java/com/github/pockethub/android/accounts/AccountUtils.java