Extract contact list in vcf format

前端 未结 4 798
渐次进展
渐次进展 2020-12-09 23:46

How could i run the android method that extract the contact list in a vcf format?
Is there an intent that can directly call this action?

thx François

4条回答
  •  一向
    一向 (楼主)
    2020-12-10 00:50

    This may be helpful to you. Try this with your need -

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

提交回复
热议问题