如何打开联系人并让用户决定是否 he/she 想要创建或 select 一个联系人

How to open contacts and let user decide if he/she want to create or select one contact

我正在尝试打开联系人并让用户决定 he/she 是要 创建 还是 select 在我的应用程序上使用它的联系人。

我需要这样的东西:

用户可以在第一个选项中添加新联系人的位置。

我尝试了以下代码:

Intent i = new Intent(Intent.ACTION_INSERT_OR_EDIT);
i.setType(ContactsContract.Contacts.CONTENT_TYPE);
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, CARREGA_CONTATOS);

但是在 Logcat 上遇到了这个错误(就在 startActivityForResult 之后):

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT_OR_EDIT typ=vnd.android.cursor.dir/contact (has extras) }

我做错了什么?

编辑:

我试过这段代码也得到了类似的结果:

Intent intent = new Intent(
    Intent.ACTION_INSERT_OR_EDIT,
    ContactsContract.Contacts.CONTENT_URI
);
startActivityForResult(intent, CARREGA_CONTATOS);

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT_OR_EDIT dat=content://com.android.contacts/contacts }

编辑 2: 几乎是我需要的:

Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, CARREGA_CONTATOS);

但是这段代码打开这张图片,用户必须 select "Contacts" 才能到达我想要的位置。

documentation 似乎建议使用:

// Creates a new Intent to insert a contact
Intent intent = new Intent(Intents.Insert.ACTION);
// Sets the MIME type to match the Contacts Provider
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

通常你必须添加默认类别intent.addCategory(Intent.CATEGORY_DEFAULT) 让它匹配一个动作。

你试过这个吗:

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
startActivity(intent);