Pra*_*dam 3 android vcf android-contacts
我.vcf使用下面的代码创建Android中所有联系人的文件.
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何.vcf在Android中以编程方式从文件添加/恢复联系人?
我想.vcf使用代码将该文件中的所有联系人恢复到Android.这该怎么做?
实际上我也想做同样的事情,经过长时间的研究,我终于得到了解决方案.
这是要恢复的代码段:
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);
Run Code Online (Sandbox Code Playgroud)
请享用!!
| 归档时间: |
|
| 查看次数: |
9668 次 |
| 最近记录: |