国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

Android根據電話號碼獲得聯系人頭像實例代碼

2024-04-27 13:53:49
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了Android根據電話號碼獲得聯系人頭像實例代碼,是Android程序開發中非常重要的技巧,需要的朋友可以參考下
 
 

在日常Android手機的使用過程中,根據電話號碼獲得聯系人頭像,是經常會碰到的問題。本文即以實例形式講述了Android根據電話號碼獲得聯系人頭像是實現代碼。分享給大家供大家參考之用。具體方法如下:

首先,通過ContentProvider,可以訪問Android中的聯系人等數據。常用的Uri有:

聯系人信息Uri:content://com.android.contacts/contacts
聯系人電話Uri:content://com.android.contacts/data/phones
聯系人郵件Uri:content://com.android.contacts/data/emails

并且提供了根據電話號碼獲取data表數據的功能,方法為:data/phones/filter/號碼,返回一個數據集。再通過數據集獲得該聯系人的contact_id,根據contact_id打開頭像圖片的InputStream,最后用BitmapFactory.decodeStream()獲得聯系人的頭像。

具體功能代碼如下:

// 根據號碼獲得聯系人頭像public static void get_people_image(String x_number){     // 獲得Uri  Uri uriNumber2Contacts = Uri.parse("content://com.android.contacts/"      + "data/phones/filter/" + x_number);   // 查詢Uri,返回數據集  Cursor cursorCantacts = context.getContentResolver().query(      uriNumber2Contacts,       null,       null,                  null,       null);  // 如果該聯系人存在  if (cursorCantacts.getCount() > 0) {     // 移動到第一條數據          cursorCantacts.moveToFirst();          // 獲得該聯系人的contact_id           Long contactID = cursorCantacts.getLong(cursorCantacts.getColumnIndex("contact_id"));          // 獲得contact_id的Uri           Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactID);          // 打開頭像圖片的InputStream          InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);           // 從InputStream獲得bitmap          bmp_head = BitmapFactory.decodeStream(input);   }<br>}

希望本文所述對大家的Android程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 郯城县| 雅安市| 阿尔山市| 紫云| 利津县| 乌拉特中旗| 新营市| 元阳县| 龙川县| 瑞金市| 安远县| 宜兴市| 兴安盟| 库伦旗| 阿拉善右旗| 西青区| 楚雄市| 濮阳县| 黔南| 安福县| 蒙自县| 太仓市| 平邑县| 宁强县| 司法| 敦化市| 石屏县| 黑水县| 洛浦县| 稷山县| 佛坪县| 柳州市| 霍山县| 大同县| 长乐市| 察哈| 抚宁县| 曲沃县| 阳山县| 沙坪坝区| 海兴县|