如何从contentprovider获取联系人,其中contact_id最大值为特定数字

时间:2018-07-09 09:26:08

标签: android android-contentprovider android-query

我想获取ID大于特定号码的所有联系人。

我的代码是:

    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);

但是它不起作用。

1 个答案:

答案 0 :(得分:0)

  

通过以下方式实现片段或活动   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();
        }



    }