Android的电子名片串联系电子名片、Android

2023-09-12 09:19:47 作者:别碰,嫌脏

我不知道是否有一个干净的方式导入电子名片作为一个机器人的接触。我有一个电子名片解析器,但映射每个可能的vCard字段,字段类型将是一个痛苦的,容易出错的工作。有没有更好的办法?

这是Android的接触看起来很像一个电子名片,所以我怀疑他们使用电子名片内部。没有公共API这个但是。

解决方案   

这是Android的接触看起来很像一个电子名片,所以我怀疑他们使用电子名片的内部。

我觉得这是一个很大比使用电子名片内部特别是作为vCard是有效地只是一个文本文件格式,使得效率低下的存储和更使搜索其中大量的更为复杂。

的ContactsContract (请注意我砍它在一点上,它提到了三层数据模型')

  

概述

     

ContactsContract定义的接触相关的信息的可扩展数据库。联系信息存储在一个三层数据模型:

据我可以告诉有一种方法来提取物涉及个人接触的电子名片,但我不知道的人来从电子名片的联系人。

编辑: WRT点击浏览器中的链接时,导入电子名片 - 是的,好点。我可以证实,它通过蓝牙接收至少一个电子名片(这是当然,很合乎逻辑的),当工作。如果我开放的名片上我的电话,我得到一个选择器问我,如果我想使用文件编辑器或人(宏达电接触应用程序 - 不知道这是否就是所谓的其他手机一样)。如果只有一个电子名片然后它进口无需进一步提示。如果有一个以上的,我得到另一个选择器询问我是否要导入一个/多个/全部(多提供了另一个选择器与复选框,使我的选择)。

电子名片 for Android 2.x

在理论上我想,这也许可以有倾倒在了某个目录里.vcf文件的整体负荷,写一些code,它简单地创建了一个意向,以他们的开放之一,并使用与startActivity ()不指定要使用的活动。我不知道它的意图行动将在这里被使用,但我将开始与ACTION_VIEW - 其他的选择可能是ACTION_EDIT或(云林)ACTION_RUN

虽然这在已知的环境中工作,特别是一次性的,这是一个有点乱,行为/结果可能会与不同的手机中,Android和联系人应用程序的版本有所不同。

EDIT2: WRT使用的意图来处理.vcf文件,我只试了一下,从我的SD卡 - 我不知道该怎么做,而不先保存它。下面抄录正是我所看到的,当我打开的Via蓝牙发送电子名片......

 意向书我=新意图();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(文件:///mnt/sdcard/downloads/bluetooth/MickeyMouse.vcf),文/ X-名片);
startActivity(ⅰ);
 

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?

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

解决方案

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

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.

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

Overview

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

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.

EDIT: 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).

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.

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.

EDIT2: 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);

 
精彩推荐
图片推荐