Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AccountManager return empty accounts

I have an app which is implementing my own Authenticator as described in this article. And it works fine as intended. Now I need to get google account from AccountManager and I am doing it this way:

 Account[] accounts = AccountManager.get(this).getAccountsByType("com.google");

The problem is that it return an empty array. But when I am using this snippet in my test app without all Authenticator stuff it works like a charm. I can't see where is an actual difference between these cases. Has anybody faced with this issue?

like image 996
Geralt_Encore Avatar asked Dec 25 '22 11:12

Geralt_Encore


1 Answers

My guess is that you lack the GET_ACCOUNTS permission. You can get your own app's accounts without it but access to other accounts requires permission.

It's a bit more complex than simply requesting GET_ACCOUNTS in the manifest these days because of runtime permissions. Now you have to request them dynamically, and the message shown to users for GET_ACCOUNTS is pretty cryptic (it asks for access to contacts, since it's part of the contacts permission group).

You may want to look into using AccountPicker (from Google Play Services), which requires no permissions. It presents a dialog to the user with the requested accounts (and gives an option to add a new account, too).

like image 181
Dan Lew Avatar answered Jan 09 '23 17:01

Dan Lew