10

Is there a way to get the user's first name or entire name? I mean the user of the phone

does it require special manifest permissions?

ycomp
  • 8,316
  • 19
  • 57
  • 95

3 Answers3

17

Yep, starting in ICS you can read the profile of the device owner (which requires the READ_PROFILE permission):

http://developer.android.com/reference/android/provider/ContactsContract.Profile.html

Specifically the DISPLAY_NAME column should have their name. Or you could look up the StructuredName data item to get their GIVEN_NAME:

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.StructuredName.html

Jeff Sharkey
  • 2,473
  • 1
  • 17
  • 10
  • 1
    good to know... for when ICS actually becomes popular, lol ) but thanks, it is useful (eventually) – ycomp Feb 17 '12 at 14:33
  • 1
    @ycomp it's useful now, as it improves the experience for users that are on those devices, if the feature can't be used on older devices it can't be expected to exist there. Just use graceful degradation. – Dandre Allison Nov 12 '12 at 18:54
7

What exactly do you mean? You may be able to access the name in certain ways:

  1. You can try to access their information stored in a Google account, requiring the GET_ACCOUNTS permission
  2. You could, as Vinayak.B suggested, try to glean the info from the contacts, requiring the READ_CONTACTS and the READ_PHONE_STATE permission, although I think this is a hit-or-miss option.
  3. There is also a READ_PROFILE permission, which I think is an interesting way to go, but I don't have any experience with that, so I can't tell you whether or not it's a fruitful venture.

I would try the GET_ACCOUNTS option first, since they must have a Google account to download your app. It also seems a little less invasive to me

I really hope this answers your question, but if it doesn't, you really need to provide more information.

gobernador
  • 5,659
  • 3
  • 32
  • 51
  • yes I was thinking possibly that using the accounts was the way to go... but would not a lot of users balk at installing something that accessed their accounts info? I mean can I grab their password or something like that with GET_ACCOUNTS ? or is it just name and email I can access with it? but even if grabbing password is not possible, this flag still would sound like it is possible and so I think users might write a lot of negative comments about the app, no? – ycomp Feb 17 '12 at 14:32
  • 2
    When all else fails, put an explanation for the permissions in your app description on the market and let them decide. Personally, I appreciate a dev who is honest and says "Look, guys, I have a controversial permission, but here's what I use it for". – gobernador Feb 17 '12 at 14:42
  • 4
    Uhm.. `account.name` is the gmail address. There is no (human) name field in the account object. The GET_ACCOUNTS approach is not viable – Nilzor Nov 13 '14 at 12:50
  • 1. is not an option. That is only possible with Google+ – Roel Sep 21 '15 at 14:26
2

Do you mean from device Contact list? if yes, get the source code and which permission from here : http://tutorials-android.blogspot.in/2011/11/how-to-call-android-contacts-list.html

Vinayak Bevinakatti
  • 40,205
  • 25
  • 108
  • 139