android– 以vcf格式提取联系人列表

android– 以vcf格式提取联系人列表,第1张

概述我怎么能运行以vcf格式提取联系人列表的android方法?是否有可以直接调用此 *** 作的意图?谢谢弗朗索瓦解决方法:这可能对您有所帮助.根据您的需要尝试这个–packagecom.vcard;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importj

我怎么能运行以vcf格式提取联系人列表的android方法?
是否有可以直接调用此 *** 作的意图?

谢谢
弗朗索瓦

解决方法:

这可能对您有所帮助.根据您的需要尝试这个 –

package com.vcard;import java.io.file;import java.io.fileinputStream;import java.io.fileOutputStream;import java.util.ArrayList;import androID.app.Activity;import androID.content.res.AssetfileDescriptor;import androID.database.Cursor;import androID.net.Uri;import androID.os.Bundle;import androID.os.Environment;import androID.provIDer.ContactsContract;import androID.util.Log;import androID.vIEw.VIEw;public class VCardActivity extends Activity {    Cursor cursor;    ArrayList<String> vCard ;    String vfile;    /** Called when the activity is first created. */    @OverrIDe    public voID onCreate(Bundle savedInstanceState)     {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.main);        vfile = "Contacts" + "_" + System.currentTimeMillis()+".vcf";        /**This Function For Vcard And here i take one Array List in Which i store every Vcard String of Every Conatact         * Here i take one Cursor and this cursor is not null and its count>0 than i repeat one loop up to cursor.getcount() means Up to number of phone contacts.         * And in Every Loop i can make vcard string and store in Array List which i declared as a Global.         * And in Every Loop i move cursor next and print log in logcat.         * */        getVcardString();    }    private voID getVcardString() {        // Todo auto-generated method stub        vCard = new ArrayList<String>();        cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);        if(cursor!=null&&cursor.getCount()>0)        {            cursor.movetoFirst();            for(int i =0;i<cursor.getCount();i++)            {                get(cursor);                Log.d("TAG", "Contact "+(i+1)+"VcF String is"+vCard.get(i));                cursor.movetoNext();            }        }        else        {            Log.d("TAG", "No Contacts in Your Phone");        }    }    public voID get(Cursor cursor)    {        //cursor.movetoFirst();        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));        Uri uri = Uri.withAppendedpath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);        AssetfileDescriptor fd;        try {            fd = this.getContentResolver().openAssetfileDescriptor(uri, "r");            // Your Complex Code and you used function without loop so how can you get all Contacts Vcard.??           /* fileinputStream fis = fd.createinputStream();            byte[] buf = new byte[(int) fd.getDeclaredLength()];            fis.read(buf);            String VCard = new String(buf);            String path = Environment.getExternalStorageDirectory().toString() + file.separator + vfile;            fileOutputStream out = new fileOutputStream(path);            out.write(VCard.toString().getBytes());            Log.d("Vcard",  VCard);*/            fileinputStream fis = fd.createinputStream();            byte[] buf = new byte[(int) fd.getDeclaredLength()];            fis.read(buf);            String vcardstring= new String(buf);            vCard.add(vcardstring);            String storage_path = Environment.getExternalStorageDirectory().toString() + file.separator + vfile;            fileOutputStream mfileOutputStream = new fileOutputStream(storage_path, false);            mfileOutputStream.write(vcardstring.toString().getBytes());        } catch (Exception e1)         {            // Todo auto-generated catch block            e1.printstacktrace();        }    }}
总结

以上是内存溢出为你收集整理的android – 以vcf格式提取联系人列表全部内容,希望文章能够帮你解决android – 以vcf格式提取联系人列表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101189.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存