cursor localcursor = activity.
getcontentresolver()
.query
(contactscontract.contacts.content_uri,
newstring
, null, null, null);if
(localcursor != null && localcursor.
movetofirst()
);//根據聯絡人的id獲取此人的**號碼
cursor phonescusor = activity.
getcontentresolver()
.query
( contactscontract.commondatakinds.phone.content_uri,
phoneprojection,
contactscontract.commondatakinds.phone.contact_id +
"="+ id,
null,
null)
;//因為每個聯絡人可能有多個**號碼,所以需要遍歷
if(phonescusor != null && phonescusor.
movetofirst()
)while
(phonescusor.
movetonext()
);phonescusor.
close()
;}}while
(localcursor.
movetonext()
);localcursor.
close()
;}
// 開啟通訊錄列表頁面
intent intent =
newintent
(intent.action_pick, contactscontract.contacts.content_uri);if
(intent.
resolveactivity
(getpackagemanager()
)== null)
startactivityforresult
(intent, requestcode)
;// 獲取使用者資訊
@override
protected
void
onactivityresult
(int requestcode,
int resultcode,
@nullable intent data)
}public
static list
getusercontactinfobyuri
(activity activity, uri uri)
, null, null, null);if
(cursor != null && cursor.
getcolumncount()
>0)
, contactscontract.commondatakinds.phone.contact_id +
"="+ contactid,
null, null);if
(phonecursor != null && phonecursor.
getcolumncount()
>0)
}}catch
(exception e)
finally
if(cursor != null &&
!cursor.
isclosed()
)}return list;
}
獲取通訊錄
import contactsuilet vc cncontactpickerviewcontroller vc.delegate selfpresent vc,animated true,completion nil 取消選擇聯絡人時呼叫 func contactpickerdidcancel p...
獲取手機通訊錄
在公司裡寫了一段上傳使用者通訊錄的 寫下來,以便以後查閱 獲取手機裡的通訊錄 獲取通訊錄 param context return 返回包含使用者名稱,與號碼的arraylist public arraylistgetcontact context context phones.close alla...
獲取手機通訊錄
手機聯絡人,通過乙個服務想歪提供資料 所有手機聯絡人的資料我們會在服務裡面查詢,然後再返回給activity 首先,我們建立出 contentresolver contentresolver 的建立時通過上下文來獲取的 contentresolver cr context.getcontentres...