Get my personal data contact

I need my personal contact. In Android 4.0 and above, I have my data contact. I tried with ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, but I got all my contacts without my data contact. Any idea how to get it?

This is my code:

public String getMyName(ContentResolver resolver){

    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] columns = new String[] {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
            ContactsContract.CommonDataKinds.Phone.NUMBER};
    Cursor people = resolver.query(uri, columns, null, null, null);
    try {
        int nameIndex = people.getColumnIndex(columns[0]);
        int numberIndex = people.getColumnIndex(columns[1]);

        people.moveToFirst();
        do{
            Log.d("Contact result", "Contact name: " + people.getString(nameIndex) + " contact phone: " + people.getString(numberIndex));
        } while (people.moveToNext());
    }catch (NullPointerException e){
        Log.d("Exception", "Null pointer on get personal data");
    }
    return null;
}
+4
source share
1 answer

Ok I found a library for this.

https://gist.github.com/remelpugh/4072663

It helps to get my personal details.

0
source

Source: https://habr.com/ru/post/1627011/


All Articles