Я хочу получить 50 на 50 контактов из списка контактов.
Я пробовал for loop
, но это дает мне 10 контактов случайным образом.
Как получить 50 на 50 контактов ..Пожалуйста, помогите мне
Мой код:
ArrayList<Contact_Model> contactList = new ArrayList<Contact_Model>();
Uri uri = ContactsContract.Contacts.CONTENT_URI;
Cursor contactsCursor = getContentResolver().query(uri, null, null,
null, ContactsContract.Contacts.DISPLAY_NAME + " ASC "); // Return
if (contactsCursor.moveToFirst()) {
do {
long contctId = contactsCursor.getLong(contactsCursor.getColumnIndex("_ID"));
Uri dataUri = ContactsContract.Data.CONTENT_URI; // URI to get
Cursor dataCursor = getContentResolver().query(dataUri, null,
ContactsContract.Data.CONTACT_ID + " = " + contctId,
null, null);
// Strings to get all details
String displayName = "";
String mobilePhone = "";
String contactNumbers = "";
String cNumber = "";
String contactImage = "";
String imnage = "";
Cursor phonesCursor = null;
Person.Urls urls;
try {
Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode("Phone number"));
phonesCursor = context.getContentResolver().query(phoneUri, new String[]{ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI}, null, null, null);
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
if (dataCursor.moveToFirst()) {
try {
imnage = dataCursor.getString(1);
Log.e("detail", "==============" + imnage);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
if (dataCursor.moveToFirst()) {
displayName = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));// get
do {
for (i = 0; i < 50; i++) {
if (dataCursor. getString(dataCursor.getColumnIndex("mimetype")).equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
switch (dataCursor.getInt(dataCursor.getColumnIndex("data2"))) {
case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
break;
case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
contactNumbers = dataCursor.getString(dataCursor.getColumnIndex("data1"));
contactNumbers += mobilePhone;
int id = 1;
if (String.valueOf(contactNumbers).charAt(0) == '+') {
if (contactNumbers.length() == 13) {
String trim_num = contactNumbers.substring(3);
cNumber = trim_num;
cNumber = cNumber.replaceAll(" ", "");
Log.d("number", cNumber);
}
} else {
cNumber = contactNumbers;
cNumber = cNumber.replaceAll(" ", "");
Log.d("without + number", cNumber);
}
// break;
}
}
}
break;
} while (dataCursor.moveToNext()); // Now move to next
if (!cNumber.equals("")) {
contact = new Contact();
contact.setContctId(String.valueOf(contctId));
contact.setContactNumber(cNumber);
contact.setContactName(displayName);
contact.setContactImg(imnage);
contact.save();
contactList.add(new Contact_Model(displayName, cNumber, imnage));// Finally add
} else {
Log.d("Contact : ", "Don't add empty contact");
}
}
} while (contactsCursor.moveToNext());
}
Я также пытался LIMIT 50 в курсоре.но когда я использую LIMIT контакты недоступны
Cursor contactsCursor = getContentResolver().query(uri,
null, null, null, "LIMIT 10, " + count);
count += 10;