2

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.
10 Rep
  • 2,217
  • 7
  • 19
  • 33
klenium
  • 2,468
  • 2
  • 24
  • 47

2 Answers2

1

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

Shriyansh Gautam
  • 1,084
  • 1
  • 7
  • 13
0

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

Anshul
  • 79
  • 4