开发者

Getting the android username stored in the phone

开发者 https://www.devze.com 2023-01-09 05:46 出处:网络
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.

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

精彩评论

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