从VCF文件的android读取联系人 [英] android read contacts from vcf file

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

问题描述

<一个href="http://stackoverflow.com/questions/12798001/android-how-to-send-multiple-contacts-are-attached-in-single-vcf-file-and-send">Android如何发送多个触点被安装在单独的.vcf文件和发送到邮件?

我创建的.vcf所有往来文件,现在我想读.vcf文件这些接触,plz帮助我,PLZ DONOT给这个链接来阅读的 HTTP://$c$c.google.com/p/vcardio/

我的VCF文件为这样的创建

  BEGIN:VCARD
版本:2.1
N:;罗希特;;;
FN:罗希特
TEL; HOME;配音:855-904-6600
END:VCARD

BEGIN:VCARD
版本:2.1
N:; RKS ;;;
FN:RKS
TEL; HOME;配音:887-276-5160
END:VCARD
BEGIN:VCARD
版本:2.1
N:库马尔;罗希特;;;
FN:罗希特·库马尔
TEL; HOME;配音:981-442-3564
电子邮件,主页:rks@gmail.com
END:VCARD
 

解决方案

  VCardParser分析器=新VCardParser();
            VDataBuilder建设者=新VDataBuilder();

              //读取整个文件到串
            的BufferedReader读卡器=新的BufferedReader(新的InputStreamReader(
                    新的FileInputStream(文件),UTF-8));

            字符串vcardString =;
            串线;
            而((行= reader.readLine())!= NULL){
                vcardString + =行+\ N的;

            }
            reader.close();

            //解析字符串
            布尔解析= parser.parse(vcardString,UTF-8,建设者);
            如果(!解析){
                抛出新VCardException(无法解析vCard文件:+文件);
            }

            //获取所有解析联系人
            名单&LT; v节点&GT; pimContacts = builder.vNodeList;
            INT C = pimContacts.size();
            pDialog.setMax(C);
            //做一些对所有联系人

            对于(v节点联系人:pimContacts){
                我++;
                字符串Y =将String.valueOf(我);
                ArrayList的&LT; PropertyNode&GT;道具= contact.propList;
                //联系人姓名 -  FN物业
                字符串HomeNumber = NULL;
                字符串显示名称= NULL;
                字符串添加= NULL;
                字符串EMAILID = NULL;

                对于(PropertyNode道具:道具){
                    如果(FN.equals(prop.propName)){
                        显示名称= prop.propValue;
                        //我们有名字了
                        打破;
                    }

                }
    }
 

Android How to send multiple contacts are attached in single .vcf file and send to mail?

i have created .vcf file of all contacts, now i want to read these contacts from .vcf file, plz help me and plz donot give this link to read http://code.google.com/p/vcardio/

my vcf file is created as like this

BEGIN:VCARD
VERSION:2.1
N:;rohit;;;
FN:rohit
TEL;HOME;VOICE:855-904-6600
END:VCARD

BEGIN:VCARD
VERSION:2.1
N:;rks;;;
FN:rks
TEL;HOME;VOICE:887-276-5160
END:VCARD
BEGIN:VCARD
VERSION:2.1
N:kumar;rohit;;;
FN:rohit kumar
TEL;HOME;VOICE:981-442-3564
EMAIL;HOME:rks@gmail.com
END:VCARD

解决方案

VCardParser parser = new VCardParser();
            VDataBuilder builder = new VDataBuilder();

              //read whole file to string
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(file), "UTF-8"));

            String vcardString = "";
            String line;
            while ((line = reader.readLine())!= null) {
                vcardString += line + "\n";

            }
            reader.close();

            //parse the string
            boolean parsed = parser.parse(vcardString, "UTF-8", builder);
            if (!parsed) {
                throw new VCardException("Could not parse vCard file: " + file);
            }

            //get all parsed contacts
            List<VNode> pimContacts = builder.vNodeList;
            int c = pimContacts.size();
            pDialog.setMax(c);
            // do something for all the contacts

            for (VNode contact : pimContacts) {
                i++;
                String y = String.valueOf(i);
                ArrayList<PropertyNode> props = contact.propList;
                // contact name - FN property
                String HomeNumber = null;
                String DisplayName = null;
                String Add = null;
                String emailID = null;

                for (PropertyNode prop : props) {
                    if ("FN".equals(prop.propName)) {
                        DisplayName = prop.propValue;
                        // we have the name now
                        break;
                    }

                }
    }

这篇关于从VCF文件的android读取联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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