0

I want to get all contacts that has an id larger than a specific number.

My code is:

    String xml = "[";
    max_contact_id="1000";

    final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " ASC";

    Cursor cur = content.query(ContactsContract.Contacts.CONTENT_URI, null , ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" > ?",
            new String[]{max_contact_id}, sortOrder);

But it won't work.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • Try to decrease this number e.g. to 10, and put some projection instead null. It's hard to get number of 1000 contacts, may you just not achieve that number. – grabarz121 Jul 09 '18 at 13:35

1 Answers1

0

Implement your Fragment or Activity with LoaderManager.LoaderCallbacks

implements LoaderManager.LoaderCallbacks<Cursor> 



 @Override
    public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
        return new CursorLoader(getActivity(),
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, ProfileQuery.PROJECTION,
                // Select only email addresses
                null, null, null);
    }

@Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        cursor.moveToFirst();


        while (!cursor.isAfterLast()) {

            String phoneNumber = cursor.getString(ProfileQuery.NUMBER);
            String name = cursor.getString(ProfileQuery.NAME);
            cursor.moveToNext();
        }



    }