简体   繁体   中英

How to get the phone user's name?

My application needs the user's display name. In System Settings, under the Users section, I can see my name. That would be fine for my app. How can I get that or a similar string?

Several suggestions to how to do this I found on Stack Overflow did not work for me.

  • AccountManager returns only the email address, which I don't need.
  • ContactsContract.Contacts contains only other people data.
  • ContactsContract.Profile seems to be empty.
  • ContactsContract.Data doesn't containt that name I need.
  • I wouldn't use oAuth or such login services. My app doesn't need account management, it just needs a name of the phone owner.

You can get users email with GET_ACCOUTNS permission but for getting User Name you need to implement some OAuth to access User's Name and other profile informations.

One way is to user Google Sign-in developers.google.com/identity/sign-in/android/people

use String getUserName () method Returns the user name of the user making this call. This call is only available to applications on the system image; it requires the MANAGE_USERS permission.

for referenceClick here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM