It is not necessary to call moveToFirst , but in order for you to moveToFirst to any of the returned lines before accessing the value (see moveToLast() , moveToPosition(int position) , ...).
So this is:
Cursor cur = cr.query(Contacts.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(Contacts._ID)); final Uri uri = RawContactsEntity.CONTENT_URI;
will work too - or even better, because there is a problem with the accepted answer , if you continue with ...
while (cur.moveToNext()) {
after
if (cur.getCount() > 0) {
It will skip the first line, which may not be obvious.
Trinimon
source share