limiting number of rows in a ContentResolver.query() function

后端 未结 3 681
借酒劲吻你
借酒劲吻你 2020-12-30 19:22

Is there a way to limit the number of returned rows to a cursor? I have a phone with about 4000 contacts, I just need some of them.

this is the code i\'m using

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 19:53

    The accepted answer is not valid anymore for android 11. In android 11 a constraint was added to not allow using LIMIT in sort value. You need to use the query with bundle parameters. For instance:

            val bundle = Bundle().apply {
                putInt(ContentResolver.QUERY_ARG_LIMIT, 100)
            }
            resolver.query(
                    ContactsContract.Contacts.CONTENT_URI,
                    projection,
                    bundle,
                    null
            )
    

提交回复
热议问题