问题描述
对于我的一个应用程序,我需要用户选择他现有的联系人之一或创建一个新联系人.使用以下代码显然很容易选择一个:
For one of my apps, I need the user to select one of his existing contacts or to create a new one.Picking one is clearly easy to do with the following code:
i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT_REQUEST );
现在我想创建一个新联系人.我尝试使用该代码,但它不会触发活动结果:
Now I want to create a new contact. I tried to use that code but it doesn't trigger the activity result:
i = new Intent(Intent.ACTION_INSERT);
i.setType(Contacts.CONTENT_TYPE);
startActivityForResult(i, PICK_CONTACT_REQUEST);
以上代码将启动联系人添加表单.然后当我验证它时,它只是要求我打开联系人列表并且永远不会触发 onActivityResult 方法.
The above code will start the contact adding form. Then when I validate it, it just asks me to open the contact list and the onActivityResult method is never triggered.
你能帮我让它工作吗?
我在一些板上读到这是不可能的,我不得不创建自己的联系人添加表单.你能确认一下吗?
I read on some boards that this wasn't possible, and I had to create my own contact adding form. Could you confirm that ?
问题已解决.检查我的答案.
推荐答案
终于找到解决方案了,分享给大家.这只是对高于 4.0.3 和 sup 的 Android 版本的修复.它不适用于 4.0 到 4.0.2.
Finally found a solution, I'm sharing it with you.That's only a fix for Android version above 4.0.3 and sup. It doesn't work on 4.0 to 4.0.2.
i = new Intent(Intent.ACTION_INSERT);
i.setType(Contacts.CONTENT_TYPE);
if (Integer.valueOf(Build.VERSION.SDK) > 14)
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, PICK_CONTACT_REQUEST);
这篇关于插入新的联系意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!