java - Android 中不显示联系人照片?

标签 java android

嗨 我在 Android 中显示联系人图像时遇到问题。 以下是我使用过的代码 fragment ,

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;
}

提前致谢。

最佳答案

对于根据我的显示图像联系人,您只需执行我看到的操作即可。 复制 .png 图像 res/drawable/a_1;

并将其写在您想要看到此图像的位置.. 查看 v1=findViewById(R.drawable.a_1);

关于java - Android 中不显示联系人照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5141633/

相关文章:

Android actionbar 样式被后来的设备忽略,使用 appcompat v7

java - 如何使用 for 循环从数组的每个第 n 个元素开始循环?

java - 如何在不阻塞的情况下从嵌套的 CompletableFuture 返回值?

Java Swing绘制html格式的字符串

Android CORS 请求只能工作一次?

android - iOS 中用于渐进式 Web 应用程序的推送通知

php - Android:发送要存储在MySQL中的数据

java - 使用对话框创建施工单(每次我尝试运行它都会终止)?

java - 在 MinMaxPriorityQueue Guava 中更改比较器

android - 如何从 linux 上用 android 手机调用电话?