Android – get my personal data contact

I need to get my personal contact information. In Android 4.0 and later, we have a data contact. I have tried to use contactscontract.commondatakings.phone.display_ Name, but I received all contacts without my data contacts. Do you know 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;
}

resolvent:

OK. I found its library

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

It helps to get my personal data

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>