歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android通過查詢電話號碼獲取聯系人頭像

Android通過查詢電話號碼獲取聯系人頭像:

  1. // 取得Intent中的頭像   
  2.             ivShowImage = (ImageView) findViewById(R.id.call_log_detail_contact_img);  
  3.             //通話電話號碼獲取頭像uri   
  4.             Uri uriNumber2Contacts = Uri  
  5.                     .parse("content://com.android.contacts/"  
  6.                             + "data/phones/filter/" + strPhoneNumber);  
  7.             Cursor cursorCantacts = SApplication.nowSApplication  
  8.                     .getContentResolver().query(uriNumber2Contacts, nullnull,  
  9.                             nullnull);  
  10.             if (cursorCantacts.getCount() > 0) { //若游標不為0則說明有頭像,游標指向第一條記錄   
  11.                 cursorCantacts.moveToFirst();  
  12.                 Long contactID = cursorCantacts.getLong(cursorCantacts  
  13.                         .getColumnIndex("contact_id"));  
  14.                 Uri uri = ContentUris.withAppendedId(  
  15.                         ContactsContract.Contacts.CONTENT_URI, contactID);  
  16.                 InputStream input = ContactsContract.Contacts  
  17.                         .openContactPhotoInputStream(  
  18.                                 SApplication.nowSApplication  
  19.                                         .getContentResolver(), uri);  
  20.                 btContactImage = BitmapFactory.decodeStream(input);  
  21.                 Log.i("info""bt======" + btContactImage);  
  22.                 ivShowImage.setImageBitmap(btContactImage);  
  23.   
  24.             } else {//麼有頭像設置默認頭像   
  25.                 ivShowImage  
  26.                         .setImageResource(R.drawable.call_log_contact_image2);  
  27.   
  28.             }  
Copyright © Linux教程網 All Rights Reserved