I am trying to display contacts with search features in a RecyclerView by using the paging library. https://github.com/anujmiddha/paged-list-demo I follow this GitHub project. The following is a code snippet from my project. I am trying to fetch contacts gradually using a pagedList adapter. But this LIMIT and OFFSET is not working as expected in some Android versions such as Android 9.0. Is there any alternative to this?
private val PROJECTION = arrayOf(
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
)
val cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PROJECTION,
null,
null,
ContactsContract.Contacts.DISPLAY_NAME +
" ASC LIMIT " + limit + " OFFSET " + offset)
Also, I have tried another way as shown below.
val queryArgs = Bundle()
val cursor: Cursor?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, offset)
queryArgs.putInt(ContentResolver.QUERY_ARG_LIMIT, limit)
cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PROJECTION,
queryArgs,
null)
} else {
cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
PROJECTION,
null,
null,
ContactsContract.Contacts.DISPLAY_NAME +
" ASC LIMIT " + limit + " OFFSET " + offset)
}
But nothing works for me..