電話のすべての連絡先を .vcf ファイル (vCard) として SD カードに保存しようとしています。動作しますが、問題があります。複数の電話番号 (携帯電話番号と勤務先番号) を持つすべての連絡先は、2 回保存されます。両方の番号がそれぞれの重複する連絡先に含まれているため、正しい、重複しているだけです。誰かがこの問題を解決する方法を教えてもらえますか? 私のコードは次のとおりです。
File delete=new File(Environment.getExternalStorageDirectory()+"/Contacts.vcf");
if (delete.exists()) {
delete.delete();
}
Cursor phones = ContactService.this.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 = ContactService.this.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();
}
catch (Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
ご協力ありがとうございました。