質問

I am struggling to read out the phone/numbers etc. from the user profile. I have some previous code to read out contacts and adapted it to work with the user profile by adapting the content uri. For the name this worked:

Normal Contacts:

    Uri uri = ContactsContract.RawContactsEntity.CONTENT_URI;
    String[] projection = new String[] {
            ContactsContract.RawContactsEntity.CONTACT_ID,
            ContactsContract.RawContactsEntity.MIMETYPE,
            ContactsContract.RawContactsEntity.DATA2 };
    String selection = ContactsContract.RawContactsEntity.CONTACT_ID
            + " = ? AND " + ContactsContract.RawContactsEntity.MIMETYPE
            + " = ?";
    String[] selectionArgs = new String[] {
            "" + this.id,
            ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };

    ...

    cursor = cr.query(uri, projection, selection, selectionArgs, null);

By changing the uri to ContactsContract.RawContactsEntity.PROFILE_CONTENT_URI I managed to make the previous code work also for the user profile contact.

However, this doesn't work when trying to read out the phone numbers:

Old code:

Uri uri = ContactsContract.Data.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.Data._ID,
            ContactsContract.Data.MIMETYPE, ContactsContract.Data.DATA1,
            ContactsContract.Data.DATA2 };
    String selection = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND "
            + ContactsContract.Data.MIMETYPE + " = ?";
    String[] selectionArgs = new String[] { "" + this.rawContactID,
            ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE };

    ...

    cursor = cr.query(uri, projection, selection, selectionArgs, null);

So which uri can I use for the profile instead? I couldn't really find anything.

役に立ちましたか?

解決

I found a great solution here:

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

It includes all the code necessary.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top