添加联系人的意图不返回的数据onActivityResult下ICS [英] Add contact intent doesn't return data onActivityResult under ICS

查看:127
本文介绍了添加联系人的意图不返回的数据onActivityResult下ICS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序,以提示用户创建新的联系人,通过在Android标准的联系人界面。然后,我希望能够读取信息,新设立的接触回来。

I want my application to prompt the user to create a new contact, through the standard Contacts interface on Android. Then I want to be able to read the information back from the newly created contact.

我的code是根据添加新联系人从<一个href="http://wiresareobsolete.com/word$p$pss/2011/10/simplifying-interaction-with-contacts/">this站点。

My code is based on the "Adding A New Contact" from this site.

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, number);
startActivityForResult(intent, PICK_CONTACT);

然后

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Intent intent = new Intent(this, Foo.class);
    Uri uri = data.getData(); //I get nullpointer here on ICS
    intent.putExtra("contact", ContactAccessor.getInstance().loadContact(this, uri));
    startActivity(intent);
    finish();
}

这code正常运行在Android 2.2和2.3。它启动联系人应用程序,并允许像姓名和电子邮件地址,用户输入的东西,当他们完成,并点击确定或保存或无所谓返回到我的应用程序,我可以阅读他们进入了的东西。在Android 4.0(ICS),但是它并没有返回到我的应用程序,当用户完成创建联系人。当我退出联系人视图(通过后退键)不包括与联系人信息的任何意图。

This code runs fine on Android 2.2 and 2.3. It starts the contacts application and lets the user input stuff like name and email address and when they're done and hit "ok" or "save" or "whatever" it returns to my app and I can read the stuff they entered. On Android 4.0 (ICS) however it does not return back to my app, when the user is done creating the contact. And when I exit the contact view (through the back button) it does not include any intent with the contact information.

什么意图,我应该用它来获得ICS相同的行为?

What intent should I use to get the same behavior on ICS?

推荐答案

为Android 4.0.3及以上者,则需​​要提供新的额外的意图:

For Android 4.0.3 and up, you need to provide a new intent extra:

公共静态最后弦乐INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED =finishActivityOnSaveCompleted;

public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED = "finishActivityOnSaveCompleted";

intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED,真);

intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);

我没有为Android 4.0的解决方案4.0.2。

I don't have a solution for Android 4.0 to 4.0.2.

有人吗?

这篇关于添加联系人的意图不返回的数据onActivityResult下ICS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆