[英]How to save a contact in phone via intent? Or something using android studio?
I am working on a business card reader app for digitalizing purposes. 我正在开发用于数字化目的的名片读取器应用程序。 I have successfully got the recognition result in the form of XML. 我已经成功获得了XML形式的识别结果。 I have also parsed that XML file and extracted out the fields such as name, email, mobile no. 我还解析了该XML文件,并提取了名称,电子邮件,移动电话号码等字段。
How can I save this data in my phone contact via my app? 如何通过我的应用程序将这些数据保存在电话联系人中?
// 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);
/*
* Inserts new data into the Intent. This data is passed to the
* contacts app's Insert screen
*/
// Inserts an email address
intent.putExtra(Intents.Insert.EMAIL, mEmailAddress.getText())
/*
* In this example, sets the email type to be a work email.
* You can set other email types as necessary.
*/
.putExtra(Intents.Insert.EMAIL_TYPE, CommonDataKinds.Email.TYPE_WORK)
// Inserts a phone number
.putExtra(Intents.Insert.PHONE, mPhoneNumber.getText())
/*
* In this example, sets the phone type to be a work phone.
* You can set other phone types as necessary.
*/
.putExtra(Intents.Insert.PHONE_TYPE, Phone.TYPE_WORK);
Source: Insert a New Contact Using an Intent 来源: 使用意图插入新联系人
看一下Contacts Provider 。
Create a new Intent
: 创建一个新的Intent
:
Intent intent = new Intent(Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
Put some Extras
in your intent like EMAIL or PHONE_TYPE : 在您的意图中添加一些Extras
,例如EMAIL或PHONE_TYPE :
intent.putExtra(Intents.Insert.EMAIL, "email@email.com");
intent.putExtra(Intents.Insert.PHONE, "15417543010");
and don't forget at the end to start the Activity
: 并且不要忘记最后开始Activity
:
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.