本文介绍了如何导入或从插入.vcf文件接触,机器人编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建的.vcf 使用下面code在Android中的所有联系人的文件。

I create .vcf file of all contacts in Android using below code.

public static void getVCF()
{
    final String vfile = "POContactsRestore.vcf";
    Cursor phones = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                    null, null, null);
    phones.moveToFirst();
    for(int i =0;i<phones.getCount();i++)
    {
         String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
         Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
         AssetFileDescriptor fd;
         try
         {
             fd = mContext.getContentResolver().openAssetFileDescriptor(uri, "r");
             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 mFileOutputStream = new FileOutputStream(path, true);
                        mFileOutputStream.write(VCard.toString().getBytes());
             phones.moveToNext();
             Log.d("Vcard",  VCard);
         }
         catch (Exception e1)
         {
              // TODO Auto-generated catch block
              e1.printStackTrace();
         }
    }
}

如何添加/恢复从的.vcf 联系人在Android的编程文件?

How to add / restore contacts from .vcf file programatically in Android?

我要恢复所有联系人形成的.vcf 使用code文件中的Andr​​oid。如何做到这一点?

I want to restore all contacts form that .vcf file in to Android using code.How to do this?

推荐答案

其实我也很想做同样的一个经过长期的研究我终于得到了解决。

Actually I also want to do the same and a after a long research finally i got the solution.

下面是一张code还原:

Here is the piece of code to restore:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(storage_path+vfile)),"text/x-vcard"); //storage path is path of your vcf file and vFile is name of that file.
startActivity(intent);

享受!

这篇关于如何导入或从插入.vcf文件接触,机器人编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:12