tags:

views:

73

answers:

1

I am writing an application that requires to retrieve the android username [email protected] from the phone. I have been looking at AccountManager class. This is what I have for now 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 am getting a caller uid 10085 is different than the authenticator's uid exception. Anyone knows how to do it?

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

A: 

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

This method requires the caller to hold the permission GET_ACCOUNTS.

Make sure your application manifest has this line:

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

Hamy