歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android通過查詢電話號碼獲取聯系人頭像

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

日期:2017/3/1 10:17:58   编辑:Linux編程

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, null, null,
  9. null, null);
  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. } else {//麼有頭像設置默認頭像
  24. ivShowImage
  25. .setImageResource(R.drawable.call_log_contact_image2);
  26. }
Copyright © Linux教程網 All Rights Reserved