在图像视图中显示联系人图像

发布于 2024-12-29 20:14:13 字数 2772 浏览 3 评论 0原文

我想获取联系人图像并将其显示在图像视图中。我希望它能够根据用户选择的联系人来工作。我有一个按钮,用户按下它即可获取联系电话号码并将其显示在文本字段中。但现在我需要它来获取照片并显示它。有人知道我如何操纵它来获取照片吗? (忽略显示电子邮件的日志和显示电子邮件的变量,我操纵了代码,因此它获取了电话号码。)

case CONTACT_PICKER_RESULT:
                Cursor cursor = null;
                String email = "";
                try {
                    Bundle extras = data.getExtras();
                    Set<String> keys = extras.keySet();
                    Iterator<String> iterate = keys.iterator();
                    while (iterate.hasNext()) {
                        String key = iterate.next();
                        Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
                    }

                    Uri result = data.getData();
                    Log.v(DEBUG_TAG,
                            "Got a contact result: " + result.toString());

                    // get the contact id from the Uri
                    String id = result.getLastPathSegment();

                    // query for everything email
                    cursor = getContentResolver().query(Phone.CONTENT_URI,
                            null, Phone.CONTACT_ID + "=?", new String[] { id },
                            null);

                    int emailIdx = cursor.getColumnIndex(Phone.DATA);

                    // let's just get the first email
                    if (cursor.moveToFirst()) {

                        /*
                         * Iterate all columns. :) String columns[] =
                         * cursor.getColumnNames(); for (String column :
                         * columns) { int index = cursor.getColumnIndex(column);
                         * Log.v(DEBUG_TAG, "Column: " + column + " == [" +
                         * cursor.getString(index) + "]"); }
                         */

                        email = cursor.getString(emailIdx);

                        Log.v(DEBUG_TAG, "Got email: " + email);

                    } else {
                        Log.w(DEBUG_TAG, "No results");
                    }
                } catch (Exception e) {
                    Log.e(DEBUG_TAG, "Failed to get email data", e);
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                    EditText emailEntry = (EditText) findViewById(R.id.txtPhoneNo);
                    emailEntry.setText(email);
                    if (email.length() == 0) {
                        Toast.makeText(this, "No email found for contact.",
                                Toast.LENGTH_LONG).show();
                    }

                }

                break;
            }

        } else {
            Log.w(DEBUG_TAG, "Warning: activity result not ok");
        }
    }

I want to get a contacts image and display it in an imageview. I want this to work based on what contact the user chooses. I have a button that has the user press it and get contact phone number and display it in a text field. but now i need it to get a photo and display it. does anybody have an idea of how i can manipulate this to get photos?
(ignore the logs that say email and my variables that say email, i manipulated the code so it gets phone numbers instead.)

case CONTACT_PICKER_RESULT:
                Cursor cursor = null;
                String email = "";
                try {
                    Bundle extras = data.getExtras();
                    Set<String> keys = extras.keySet();
                    Iterator<String> iterate = keys.iterator();
                    while (iterate.hasNext()) {
                        String key = iterate.next();
                        Log.v(DEBUG_TAG, key + "[" + extras.get(key) + "]");
                    }

                    Uri result = data.getData();
                    Log.v(DEBUG_TAG,
                            "Got a contact result: " + result.toString());

                    // get the contact id from the Uri
                    String id = result.getLastPathSegment();

                    // query for everything email
                    cursor = getContentResolver().query(Phone.CONTENT_URI,
                            null, Phone.CONTACT_ID + "=?", new String[] { id },
                            null);

                    int emailIdx = cursor.getColumnIndex(Phone.DATA);

                    // let's just get the first email
                    if (cursor.moveToFirst()) {

                        /*
                         * Iterate all columns. :) String columns[] =
                         * cursor.getColumnNames(); for (String column :
                         * columns) { int index = cursor.getColumnIndex(column);
                         * Log.v(DEBUG_TAG, "Column: " + column + " == [" +
                         * cursor.getString(index) + "]"); }
                         */

                        email = cursor.getString(emailIdx);

                        Log.v(DEBUG_TAG, "Got email: " + email);

                    } else {
                        Log.w(DEBUG_TAG, "No results");
                    }
                } catch (Exception e) {
                    Log.e(DEBUG_TAG, "Failed to get email data", e);
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                    EditText emailEntry = (EditText) findViewById(R.id.txtPhoneNo);
                    emailEntry.setText(email);
                    if (email.length() == 0) {
                        Toast.makeText(this, "No email found for contact.",
                                Toast.LENGTH_LONG).show();
                    }

                }

                break;
            }

        } else {
            Log.w(DEBUG_TAG, "Warning: activity result not ok");
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友欢 2025-01-05 20:14:13

使用它

 Uri conUri=Uri.parse(url);
        InputStream photoInputStream=Contacts.openContactPhotoInputStream(mContext.getContentResolver(), conUri);
        if(photoInputStream==null)
            return framePhoto(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_contact_list_picture));
        Bitmap photo=framePhoto(getPhoto(mContext.getContentResolver(), conUri));

并了解更多信息,请访问此问题

在列表视图性能中加载联系人照片< /a>

Use it

 Uri conUri=Uri.parse(url);
        InputStream photoInputStream=Contacts.openContactPhotoInputStream(mContext.getContentResolver(), conUri);
        if(photoInputStream==null)
            return framePhoto(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_contact_list_picture));
        Bitmap photo=framePhoto(getPhoto(mContext.getContentResolver(), conUri));

And for more information go to this question

Load contact photo in a listview performance

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文