Android通讯录vcf格式,如何在Android下以编程方式从.vcf文件导入或插入联系人?

我使用下面的代码创建Android中所有联系人的.vcf文件.

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

{

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

}

}

}

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

我想使用代码将.vcf文件中的所有联系人恢复到Android.

这个怎么做?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值