javaandroidtrusted-web-activity

Trusted Web Activity [TWA] - Can it read AccountManager accounts on Android?


Problem: Attempting to read accounts created via AccountManager API in Android via a TWA LauncerActivity.

I have confirmed I have accounts on device, and am attempting a print out to Logcat of all of the accounts, but I am returned no results:

    private void printAccounts() {
        Account[] accounts = AccountManager.get(this).getAccounts();

        Log.d("FoundAccount", "Total accounts: " + accounts.length);

        for (Account account : accounts) {
            Log.d("FoundAccount", ": " + account.name);
        }
    }

Resulting output via Logcat:
D/FoundAccount: Total accounts: 0

Any resources would be greatly appreciated, thank you!


Solution

  • After running the exact same code in a pre-existing Android application, the accounts were pulled right away for Google and custom third party accounts. Safe to say this functionality doesn't exist for TWAs... if anyone else has any links to the documentation for this, I would say that is still pertinent information, but for the sake of answering this question for anyone else seeking an answer to the same question.... the answer is no, this functionality is not possible, at least at this time.