gpt4 book ai didi

android - 如何从android中的联系人获取10 -10个联系人

转载 作者:行者123 更新时间:2023-11-30 03:13:43 25 4
gpt4 key购买 nike

在我的应用程序中,我只需要获取 10 个联系人,当我按下下一步按钮时,将获取接下来的 10 个联系人......

protected String doInBackground(String... args) {
i = 0;
count = 0;
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);

names = new String[cur.getCount()];
phone = new String[cur.getCount()];

if ((cur.getCount() > 0)) {

if (count < 5) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

if (Integer
.parseInt(cur.getString(cur
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?",
new String[] { id }, null);

while (pCur.moveToNext() && i < 5) {
String phoneNo = pCur
.getString(pCur
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

names[i] = name;
phone[i] = phoneNo;
if (i == 0)
fulldata += "\"" + i + "\"" + ":" + "{"
+ "\"" + "phone" + "\"" + ":"
+ "\"" + phoneNo + "\"" + "}";
else
fulldata += "," + "\"" + i + "\"" + ":"
+ "{" + "\"" + "phone" + "\"" + ":"
+ "\"" + phoneNo + "\"" + "}";
i++;
}
pCur.close();
}

count++;
}
}
}
return null;
}

// {_action:addcontacts,contacts:{"0":{"phone":"8098098"},"1":{"phone":"8098090"},"2":{"phone":"8096879"}}}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
fulldata += "}";
Log.i("all data to post", "" + fulldata);
new UpdateContacts().execute();
}
}

我正在从此代码块中获取所有联系人,但我需要获取列表中特定(10)个联系人,当我点击下一步按钮时,它应该获取下一个(10 个数字)列表

最佳答案

我会选择 LIMIT 函数。

SELECT * FROM table LIMIT 10 --> 获取前 10 条记录

SELECT * FROM table LIMIT 10, 10 --> 在第 10 行之后获取 10 条记录

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, "LIMIT 10, " + count);
count += 10;

希望这对您有所帮助。

关于android - 如何从android中的联系人获取10 -10个联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20501375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com