Cursor cx =
getContentResolver().query(RawContacts.CONTENT_URI,
new String[]{RawContacts._ID},
null, null, null);
if(cx.moveToFirst()){
do{
Uri rawContactUri =
ContentUris.withAppendedId(RawContacts.CONTENT_URI, cx.getLong(0));
Uri entityUri = Uri.withAppendedPath(rawContactUri,
Entity.CONTENT_DIRECTORY);
Cursor c = getContentResolver().query(entityUri,
new String[]{RawContacts.SOURCE_ID,
Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
Entity.MIMETYPE + "=? OR " + Entity.MIMETYPE +
"=?",
new String[]
{ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE},
null);
try {
String name = "";
String phoneNumber = "";
while (c.moveToNext()) {
String sourceId = c.getString(0);
if (!c.isNull(1)) {
String mimeType = c.getString(2);
if(mimeType.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE))
{
name = c.getString(3); //this is the
name
}
else
if(mimeType.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE))
{
phoneNumber = c.getString(3);
}
}
}
Log.d("CONTACT", name + " - " + phoneNumber);
} finally {
c.close();
}
}while(cx.moveToNext());
}
============================
What exactly do you want to do? If you can specify more clearly (or
show the code you did with Contacts.People, then may be I can suggest
smaller code snippet.
Regards
Sarwar Erfan
On Aug 2, 11:53 am, "A N K ! T" <[email protected]> wrote:
> when i am using this class it is written there use contactscontract but
> am not getting how to use this class to fetch contacts number from
> phone.....
>
> --
>
> A N K ! T......
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en