在我的應用我需要獲取只有10聯繫人和未來10個觸點接觸,從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號)號碼列表
我想從我的手機的聯繫人直接取得聯繫。 是否工作? – AndyBoy
是的,它應該工作,試試吧.... – Husky
okey thanks @Husky – AndyBoy