android - 如何显示设备主要联系人查看器以显示一个联系人的电话号码

标签 android android-contacts

我正在编写一个应用程序,我需要向用户显示一个联系人。我有电话号码,我可以查询以获取联系方式。像这样:

ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
            Uri.encode(phoneNumber));
    Cursor cursor = cr.query(uri,
            new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);
    if (cursor == null) {
        return null;
    }
    String contactName = phoneNumber;
    if (cursor.moveToFirst()) {
        contactName = cursor.getString(cursor
                .getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
    }

但我需要显示 DEVICE 主要联系人查看器,但我不知道怎么做?

像这样:

enter image description here

最佳答案

这一切都记录在官方 Android 文档中,Common Intents , “通讯录/人脉应用”一章。

编辑

But unfortunately I can not access to your link , nor google documents also in my area !!

以下是链接文档的引述:

查看联系人

要显示已知联系人的详细信息,请使用 ACTION_VIEW 操作并指定具有内容的联系人:URI 作为 Intent 数据。

主要有两种方法来初始检索联系人的 URI:

  • 使用上一节中显示的 ACTION_PICK 返回的联系人 URI(此方法不需要任何应用权限)。
  • 直接访问所有联系人列表,如检索联系人列表中所述(此方法需要 READ_CONTACTS 权限)。

例子:

public void viewContact(Uri contactUri) {
    Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

编辑现有联系人

要编辑已知联系人,请使用 ACTION_EDIT 操作,指定具有内容的联系人:URI 作为 Intent 数据,并在 ContactsContract.Intents.Insert 中的常量指定的 extras 中包含任何已知联系人信息。

主要有两种方法来初始检索联系人 URI:

  • 使用上一节中显示的 ACTION_PICK 返回的联系人 URI(此方法不需要任何应用权限)。

  • 直接访问所有联系人列表,如检索联系人列表中所述(此方法需要 READ_CONTACTS 权限)。

注意:Extras - 在 ContactsContract.Intents.Insert 中定义的一个或多个 extras,因此您可以填充联系人详细信息的字段。

public void editContact(Uri contactUri, String email) {
    Intent intent = new Intent(Intent.ACTION_EDIT);
    intent.setData(contactUri);
    intent.putExtra(Intents.Insert.EMAIL, email);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

有关如何编辑联系人的更多信息,请阅读 Modifying Contacts Using Intents .

关于android - 如何显示设备主要联系人查看器以显示一个联系人的电话号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34894611/

相关文章:

android - RelativeLayout.BELOW 不工作

android - mvvmcross videoview URL 绑定(bind)

android - sqlite android提取带有电话号码的联系人

android - 直接用联系人应用程序打开 .vcf vCard 文件

android - 使用 Universal Image Loader 加载联系人照片

java - 无法在 Android 上使用 XOAUTH 连接到 Gmail IMAP

android - 避免按钮多次快速点击

android - 如何更改自定义 Android 键盘中 KeyboardView 类中按键的颜色?

android - Android中选择有特殊要求的RawContacts

android - Contact Image - Android 中分辨率较低