【问题标题】:Android. Opening a contact in through intent using contact_id or contact_name安卓。使用 contact_id 或 contact_name 通过意图打开联系人
【发布时间】:2012-03-08 10:03:56
【问题描述】:

我在 Android 中使用 ContactsContract API 来获取联系人列表。工作正常。

现在我希望当我单击该列表中的一个名称时会生成一个意图,该意图将在 android 联系人管理器中打开该联系人。

The following code crashes the app:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_URI + "/" + ContactsContract.Contacts._ID));

请帮我解决这个问题

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    这应该会在 android 联系人管理器中显示联系人“卡片”

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
    context.startActivity(intent);
    

    【讨论】:

    • 我建议使用intent.setDataAndType(uri, "vnd.android.cursor.dir/contact") - 如果有多个应用程序适用于显示联系人,那么用户将看到带有应用程序列表的选择器对话框。如果您使用intent.setData(uri),则不会显示选择器。
    猜你喜欢
    • 1970-01-01
    • 2014-09-06
    • 2011-03-11
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多