Android根據(jù)電話號碼獲得聯(lián)系人頭像實例代碼
在日常Android手機的使用過程中,根據(jù)電話號碼獲得聯(lián)系人頭像,是經(jīng)常會碰到的問題。本文即以實例形式講述了Android根據(jù)電話號碼獲得聯(lián)系人頭像是實現(xiàn)代碼。分享給大家供大家參考之用。具體方法如下:
首先,通過ContentProvider,可以訪問Android中的聯(lián)系人等數(shù)據(jù)。常用的Uri有:
聯(lián)系人信息Uri:content://com.android.contacts/contacts
聯(lián)系人電話Uri:content://com.android.contacts/data/phones
聯(lián)系人郵件Uri:content://com.android.contacts/data/emails
并且提供了根據(jù)電話號碼獲取data表數(shù)據(jù)的功能,方法為:data/phones/filter/號碼,返回一個數(shù)據(jù)集。再通過數(shù)據(jù)集獲得該聯(lián)系人的contact_id,根據(jù)contact_id打開頭像圖片的InputStream,最后用BitmapFactory.decodeStream()獲得聯(lián)系人的頭像。
具體功能代碼如下:
// 根據(jù)號碼獲得聯(lián)系人頭像
public static void get_people_image(String x_number){
// 獲得Uri
Uri uriNumber2Contacts = Uri.parse("content://com.android.contacts/"
+ "data/phones/filter/" + x_number);
// 查詢Uri,返回數(shù)據(jù)集
Cursor cursorCantacts = context.getContentResolver().query(
uriNumber2Contacts,
null,
null,
null,
null);
// 如果該聯(lián)系人存在
if (cursorCantacts.getCount() > 0) {
// 移動到第一條數(shù)據(jù)
cursorCantacts.moveToFirst();
// 獲得該聯(lián)系人的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程序設(shè)計有所幫助。
- Android實現(xiàn)本地上傳圖片并設(shè)置為圓形頭像
- Android使用CircleImageView實現(xiàn)圓形頭像的方法
- Android實現(xiàn)用戶頭像更換操作
- Android實現(xiàn)從本地圖庫/相機拍照后裁剪圖片并設(shè)置頭像
- Android手機拍照或選取圖庫圖片作為頭像
- Android一行代碼實現(xiàn)圓形頭像
- Android實現(xiàn)調(diào)用系統(tǒng)圖庫與相機設(shè)置頭像并保存在本地及服務(wù)器
- Android實現(xiàn)個人資料頁面頭像背景模糊顯示包(狀態(tài)欄)
- Android頭像上傳功能的實現(xiàn)代碼(獲取頭像加剪切)
- Android實現(xiàn)IM多人員組合的群組頭像
相關(guān)文章
Android Handler中的休眠喚醒實現(xiàn)詳解
這篇文章主要為大家介紹了Android Handler中的休眠喚醒實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
Android開發(fā)實現(xiàn)ListView點擊item改變顏色功能示例
這篇文章主要介紹了Android開發(fā)實現(xiàn)ListView點擊item改變顏色功能,涉及Android布局及響應(yīng)事件動態(tài)變換元素屬性相關(guān)操作技巧,需要的朋友可以參考下2017-11-11
Android數(shù)據(jù)持久化之Preferences機制詳解
這篇文章主要介紹了Android數(shù)據(jù)持久化之Preferences機制,較為詳細(xì)的分析了Android數(shù)據(jù)持久化的概念、Preferences機制的原理與相關(guān)實現(xiàn)、使用技巧,需要的朋友可以參考下2017-05-05
anndroid使用ViewPager實現(xiàn)三個fragment切換
這篇文章主要介紹了anndroid使用ViewPager實現(xiàn)三個fragment切換,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04
Android自定義View onDraw()方法會調(diào)用兩次的問題解決
這篇文章主要介紹了Android自定義View onDraw()方法會調(diào)用兩次的問題解決,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01
android頂部(toolbar)搜索框?qū)崿F(xiàn)代碼
這篇文章主要介紹了android頂部(toolbar)搜索框?qū)崿F(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01

