需求 : 獲取本地通訊錄中的聯絡人資料
實現 : 通過系統定義好的常量去獲取聯絡人資料
** :
uri簡介public class contactsdao ;//返回的列名
string selection = null; //查詢的條件
string selectionargs = null;//查詢條件的引數
string sortorder = null; //排序
cursor cursor = contentresolver.query(uri, projection, selection, selectionargs, sortorder);
if(cursor!=null)
//關閉
cursor.close();
}return datas;
}//獲取聯絡人頭像的bitmap content://com
.android
.contacts
public static bitmap getbitmap(context context, string id)
}
聯絡人**uri: content:
聯絡人email uri: content:
android官方有上述將上述uri進行封裝,我們可以使用api以更簡單的方式獲取這些uri
聯絡人**uri: contactscontract.commondatakinds.phone.content_uri
聯絡人名字列名常量:contactscontract.commondatakinds.phone.display_name
聯絡人號碼列名常量:contactscontract.commondatakinds.phone.number
聯絡人id列名常量: contactscontract.commondatakinds.phone.contact_id
讀取聯絡人需要新增許可權
寫許可權需求 : 獲取聯絡人的
實現 : 通過 contactscontract.contacts.opencontactphotoinputstream()方法獲取檔案流, 然後通過bitmapfactory獲取對應的bitmap
** :
public
static bitmap getphoto(context context, string id)
讀取手機聯絡人,複雜 姓名,電話,郵箱
增加許可權,讀取聯絡人,和新增新增聯絡人,根據自己需求新增 raw contacts 這個表中存放的是聯絡人的id data 這個表中存放的是聯絡人的資訊,例如 姓名 郵箱 自定義方法查詢手機聯絡人 private void selectcontact null person p new perso...
獲取聯絡人頭像
首先設定需要獲取的資料 private static final string phones projection new string 其中上面的photo id可以判斷是否存在頭像,當大於0是表示存在頭像。通過下面查詢資料 contentresolver resolver mcontext.ge...
顯示聯絡人的頭像
顯示聯絡人頭像。判斷phone.photo id是否為0,如果為0表示沒有設定頭像,就使用預設的聯絡人頭像,否則就使用使用者設定的頭像。private void setdefaultphoto viewholder holder,boolean bsim if defaultsimphoto nul...