开发者

Getting the android username stored in the phone

I am writing an application that requires to retrieve the android username username@gmail.com 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 kn开发者_如何转开发ows how to do it?

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


Username is available to you; just use:

String email = accounts[0].name;


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" />

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜