2017-05-27 2 views
0

Ich fand diesen Code um das Forum für die Erstellung einer VCF-Datei mit allen Kontakten im Telefon gespeichert. Nun, ich bekomme alle Kontakte, aber duplicate weiß jemand, wie man es repariert? Ich bin nur daran interessiert, die in den Kontakten angezeigt Kontakte Buch nicht Kontakte google usw. DANKdoppelte Kontakte als vcf Datei 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 

Antwort

0

nur die Lösung bearbeiten Frage gefunden:

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