重复的联系人为vcf文件android

问题描述:

我发现这个代码围绕论坛创建一个vcf文件,存储在手机中的所有联系人。以及我得到所有联系人,但重复没有人知道如何解决它?我只在联系人中显示的联系人感兴趣的书不是Google联系人等。由于重复的联系人为vcf文件android

private void getVcardString() throws IOException { 
      // TODO Auto-generated method stub 
      //ProgressBar pro = (ProgressBar)findViewById(R.id.pb); 

      // ProgressBar pro = (ProgressBar) findViewById(R.id.pb1); 
      vCard = new ArrayList<String>(); // Its global.... 
      cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1", 
        null, null, null); 
      if (cursor != null && cursor.getCount() > 0) { 
       int i; 
       String storage_path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile; 
       FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, false); 
       cursor.moveToFirst(); 
       for (i = 0; i < cursor.getCount(); i++) { 

        get(cursor); 
        Log.d("TAG", "Contact " + (i + 1) + "VcF String is" + vCard.get(i)); 
        cursor.moveToNext(); 

        mFileOutputStream.write(vCard.get(i).toString().getBytes()); 
       } 
       mFileOutputStream.close(); 
       cursor.close(); 
       new Handler(Looper.getMainLooper()).post(new Runnable() { 
        @Override 
        public void run() { 
         tx.setText(""); 
         pro.setVisibility(View.GONE); 
         btn3.setVisibility(View.VISIBLE); 
         tx1.setVisibility(View.VISIBLE); 
         Toast toast=Toast.makeText(getApplicationContext(),"בוצע גיבוי לכרטיס הזיכרון",Toast.LENGTH_SHORT); 
         toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0,90); 
         toast.show(); 

        } 
       }); 




      } else { 
       Log.d("TAG", "No Contacts in Your Phone"); 
      } 
     } 

     private void get(Cursor cursor2) { 
      String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); 
      Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey); 
      AssetFileDescriptor fd; 
      try { 
       fd = getContentResolver().openAssetFileDescriptor(uri, "r"); 

       FileInputStream fis = fd.createInputStream(); 
       byte[] buf = new byte[(int) fd.getDeclaredLength()]; 
       fis.read(buf); 
       String vcardstring = new String(buf); 
       vCard.add(vcardstring); 

      } catch (Exception e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } 
     } 

    }); 
} here 

只是找到解决方案编辑查询:

getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);