繁体   English   中英

如何通过意图在电话中保存联系人? 还是使用Android Studio的东西?

[英]How to save a contact in phone via intent? Or something using android studio?

我正在开发用于数字化目的的名片读取器应用程序。 我已经成功获得了XML形式的识别结果。 我还解析了该XML文件,并提取了名称,电子邮件,移动电话号码等字段。

如何通过我的应用程序将这些数据保存在电话联系人中?

// 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);

来源: 使用意图插入新联系人

看一下Contacts Provider

创建一个新的Intent

Intent intent = new Intent(Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);

在您的意图中添加一些Extras ,例如EMAILPHONE_TYPE

intent.putExtra(Intents.Insert.EMAIL, "email@email.com");
intent.putExtra(Intents.Insert.PHONE, "15417543010");

并且不要忘记最后开始Activity

startActivity(intent);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM