Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get firstname and lastname of Android phone owner?

Is there a way to get the firstname and lastname of Android phone owner? I've search the internet but I have no luck. I stumbled upon this question in Stackoverlow but this is getting firstname and lastname of all contacts. What I need is just to get the owner's firstname and lastname.

like image 879
silent_coder14 Avatar asked Oct 26 '12 10:10

silent_coder14


People also ask

How to find my Android phone name?

Open the Settings app to check your device information: Tap About phone. Take note of your device name.

How to find device name on Android tablet?

How do I find out my Android tablet's model name, its Android version and the Connect Android app version? Open 'Settings' and then 'About tablet' on the bottom left side. Then you will find 'Device name' (e.g. “Galaxy Tab A (2016)”) and 'Model number' (e.g. “SM-T585”) below.


1 Answers

I think this is available ICS onwards only - Look at this for more info http://android-codelabs.appspot.com/resources/tutorials/contactsprovider/ex1.html

Cursor c = activity.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
int count = c.getCount();
String[] columnNames = c.getColumnNames();
boolean b = c.moveToFirst();
int position = c.getPosition();
if (count == 1 && position == 0) {
    for (int j = 0; j < columnNames.length; j++) {
        String columnName = columnNames[j];
        String columnValue = c.getString(c.getColumnIndex(columnName)));
        ...
        //Use the values
    }
}
c.close();

Android includes a personal profile that represents the device owner - this profile is known as the "Me" profile and is stored in the ContactsContract.Profile table. You can read data from the user's profile so long as you

add the READ_PROFILE and READ_CONTACTS permission in your AndroidManifest.xml.

The most relevant fields for you are the DISPLAY_NAME column from the Contact and possibly the StructuredName fields

like image 109
Vrashabh Irde Avatar answered Oct 04 '22 05:10

Vrashabh Irde