开发者

Problem with ContactsContract.Intents.SHOW_OR_CREATE_CONTACT

开发者 https://www.devze.com 2023-03-13 08:20 出处:网络
I have a problem trying to work with Contacts. I use the code below to add new Comtacts and it works OK. However if I press the hard Back button on the Add Contact screen, the con开发者_如何学Pythonta

I have a problem trying to work with Contacts. I use the code below to add new Comtacts and it works OK. However if I press the hard Back button on the Add Contact screen, the con开发者_如何学Pythontact is added as if I have pressed Done/Save. What can I do so that Back is treated as Cancel and not as Done/Save? Thanks.

Intent i = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse(String.format("tel: %s", number)));
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true);
i.putExtra(ContactsContract.Intents.Insert.NAME, name);
i.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.PHONE, number);
startActivity(i);


Since you have FORCE_CREATE set to true, most likely the contact is being created immediately. I myself am going to do something similar but I will leave force create to false. If the user elects not to add the contact, I am going to go ahead and show them a simple "dial now" screen so they can do a one-time dial. Might work for your situation. I am fetching additional contacts from a company web service so that's how I end up with a one-time-dial situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消