Get Android username on your phone

I am writing an application that requires getting the username android username@gmail.com from the phone. I am looking at the AccountManager class. This is what I have in my code.

AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType("com.google"); String email=""; email=accountManager.getUserData(accounts[0], accountManager.KEY_USERDATA); 

However, I get caller uid 10085 different from the uid authenticator exception. Does anyone know how to do this?

PS. I don't need a password or authentication token, I just need a username.

+7
android
source share
2 answers

Do you have the GET_ACCOUNTS permission set in your manifest file? See docs in the getAccountsByType () method:

This method requires the caller to retain GET_ACCOUNTS permission.

Make sure your application manifest has the following line:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

+2
source share

Username is available; just use:

String email = accounts[0].name;

+2
source share

All Articles