要联系的android vcard字符串 [英] android vcard string to contact

查看:55
本文介绍了要联系的android vcard字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种干净的方法可以将 vcard 作为 Android 联系人导入.我有一个 vcard 解析器,但是映射每个可能的 vcard 字段和字段类型将是一个痛苦的、容易出错的练习.有没有更好的办法?

i'm wondering if there's a clean way to import a vcard as an android contact. i have a vcard parser, but mapping each possible vcard field and field type is going to be a painful, bug-prone exercise. is there a better way?

一个 android 联系人看起来很像 vcard,所以我怀疑他们在内部使用 vcard.但是,没有为此提供公共 API.

an android contact looks suspiciously like a vcard, so i suspect they use vcards internally. there's no public API for this however.

推荐答案

一个 android 联系人看起来很像 vcard,所以我怀疑他们在内部使用 vcard.

an android contact looks suspiciously like a vcard, so i suspect they use vcards internally.

我认为这比在内部使用vCard"要复杂得多,尤其是因为 vCard 实际上只是一种文本文件格式,因此存储效率低下,而且搜索大量此类文件的效率更高.

I think it's a lot more complicated than using 'vCards internally' especially as vCard is effectively just a text file format making it inefficient to store and more so to search a large number of them.

ContactsContract 概述(注意我在这一点上剪掉了它它提到了三层数据模型")...

The Overview of ContactsContract (note I cut it at the point it mentions 'three-tier data model')...

概述

ContactsContract 定义了一个可扩展的联系人相关信息数据库.联系信息存储在三层数据模型中:

ContactsContract defines an extensible database of contact-related information. Contact information is stored in a three-tier data model:

据我所知,有一种方法可以提取"与个人联系人相关的 vCard,但我不知道有什么方法可以从 vCard 创建联系人.

As far as I can tell there is a way to 'extract' a vCard relating to an individual contact but I don't know of one to create a contact from a vCard.

在浏览器中单击链接时 WRT 导入电子名片 - 是的,很好.我可以确认它至少在通过蓝牙接收 vCard 时可以工作(当然,这是非常合乎逻辑的).如果我在手机上打开"电子名片,我会收到一个选择器",询问我是要使用文件编辑器"还是人物"(HTC 通讯录应用程序 - 不确定在其他手机上是否也这样称呼).如果只有一张 vCard,则它会在没有进一步提示的情况下导入.如果有多个,我会收到另一个选择器,询问我是否要导入 One/Multiple/All(Multiple 提供另一个带有复选框的选择器以进行选择).

WRT importing vCards when clicking a link in a browser - yes, good point. I can confirm that it works when receiving a vCard by Bluetooth at least (which is, of course, quite logical). If I 'open' the vCard on my phone, I get a 'chooser' asking me if I want to use 'File Editor' or 'People' (the HTC contacts app - not sure if it's called the same on other phones). If there is only one vCard then it imports without further prompting. If there are more than one, I get another chooser asking if I want to import One/Multiple/All (Multiple gives another chooser with checkboxes to make my selection).

理论上我想,有可能将一整套 .vcf 文件转储到某个目录中的某个位置并编写一些代码,这些代码只是创建一个 Intent 以打开"其中一个并将其与 startActivity() 一起使用,而无需指定要使用的活动.我不确定这里将使用哪个意图操作,但我会从 ACTION_VIEW 开始 - 其他选择可能是 ACTION_EDIT 或(勉强)ACTION_RUN.

In theory I suppose, it might be possible to have a whole load of .vcf files dumped in a directory somewhere and write some code which simply creates an Intent to 'open' one of them and use that with startActivity() without specifying which activity to use. I'm not sure which intent action would be being used here but I would start with ACTION_VIEW - other choices might be ACTION_EDIT or (tenuously) ACTION_RUN.

虽然这可能在已知环境中工作,特别是一次性使用,但它有点混乱,行为/结果可能因手机、Android 版本和联系人应用程序而异.

Although this may work in a known environment particularly as a one off, it is a bit messy and behaviour/results may vary with different phones, versions of Android and contacts apps.

WRT 使用 Intent 处理 .vcf 文件,我只从我的 SD 卡尝试过 - 我不知道如何在不先保存的情况下进行操作.以下内容准确再现了我打开通过蓝牙发送的电子名片时看到的内容...

WRT to using an Intent to process .vcf files, I've only tried it from my SD card - I have no idea how to do it without saving it first. The following reproduces exactly what I see when I open a vCard that's sent via Bluetooth...

Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file:///mnt/sdcard/downloads/bluetooth/MickeyMouse.vcf"), "text/x-vcard");
startActivity(i);

这篇关于要联系的android vcard字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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