2011-02-28 48 views
0

嗨 我在android系统中显示的联系人图像的问题。 以下是我用过的代码片段,联系人照片未在Android中显示?

public String getCallersInfo(ContentResolver cnt,String phoneNumber) 
{ 
    mContentResolver = cnt; 
    lNumber = phoneNumber; 

    System.out.println("Start test"); 

    Cursor l_Cur = mContentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
              null, 
              ContactsContract.CommonDataKinds.Phone.NUMBER +" = ?", 
              new String[]{lNumber }, null); 
    while (l_Cur.moveToNext()) 
    { 
     cid = l_Cur.getString(l_Cur.getColumnIndex(
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID)); 
    } 
    System.out.println("The contact ID for person with phone number "+ lNumber + " is " + cid); 

    if(!(cid.equals("Unknown"))) 
    {   
     Cursor cursor_contacts = mContentResolver.query(ContactsContract.Contacts.CONTENT_URI, 
                 null, 
                 ContactsContract.Contacts._ID + " = ?", 
                 new String[]{cid }, 
                 null); 
     while(cursor_contacts.moveToNext()) 
     { 
      displayname = cursor_contacts.getString(cursor_contacts.getColumnIndex( 
          ContactsContract.Contacts.DISPLAY_NAME)); 
      photoid = cursor_contacts.getString(cursor_contacts.getColumnIndex( 
          ContactsContract.Contacts.PHOTO_ID)); 

     } 
     System.out.println("The display name & photo id for person with phone number " 
         + lNumber + " is " + displayname + " & " + photoid); 

     Uri contactPhotoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Integer.parseInt(cid)); 

     // Uri photoUri = Uri.withAppendedPath(contactPhotoUri, Contacts.Photo.CONTENT_DIRECTORY); 

     // contactPhotoUri --> content://com.android.contacts/contacts/1557 

     InputStream photoDataStream = Contacts.openContactPhotoInputStream(mContentResolver,contactPhotoUri); // <-- always null 

     if(photoDataStream == null) 
     { 
      System.out.println("No photo available "); 
     } 

     Bitmap bt = BitmapFactory.decodeStream(photoDataStream); 

     setmPhoto(bt); 
    } 
    return displayname; 
} 

在此先感谢。

+0

嗨。检查[这](http://stackoverflow.com/questions/2383580/android-how-do-i-load-a-contact-photo)。 – Pasha 2011-02-28 12:00:08

回答

1

根据我只是你,我看到.. 复制乌尔巴纽图像RES /绘制/ A_1显示图像接触;

并写下你想看到这张图片的地方.. View v1 = findViewById(R.drawable.a_1);

+0

嗨,感谢您的回复,但我只是想阅读设备中联系人的特定照片? – 2011-02-28 12:13:51