2013-03-11 3 views
1

quand je requête simple mes contacts puis tous les contacts dans la liste montre également inclus les contacts facebook et contacts Gmail mais quand j'utiliser ce code, puis quelques uns vcard sont vides ...Non Faire VCard de contacts Facebook

  String VCard = ""; 

     Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null, null, null); 
     phones.moveToFirst(); 
     pDialog.setMax(phones.getCount()); 
      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 = getContentResolver().openAssetFileDescriptor(uri, "r"); 
       FileInputStream fis = fd.createInputStream(); 
       byte[] buf = new byte[(int) fd.getDeclaredLength()]; 
       fis.read(buf); 
       VCard += new String(buf); 
       String y =String.valueOf(i); 
       publishProgress(y); 
       phones.moveToNext();       
       Log.d("Vcard", VCard); 
      } 
      catch (Exception e1) 
      { 
        // TODO Auto-generated catch block 
        e1.printStackTrace(); 
      } 

     } 

     try { 
      FileOutputStream mFileOutputStream = new FileOutputStream(file, false); 
       mFileOutputStream.write(VCard.toString().getBytes()); 
       mFileOutputStream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

Répondre

2

ContactsContract.CommonDataKinds.Phone.CONTENT_URI est uri pour les téléphones vous devez changer pour android.provider.ContactsContract.Contacts.CONTENT_URI vous obtiendrez vcard de contact qui est pas emty

+0

et je veux, ne copiez pas le code de photo en Vcard alors qu'est-ce que je fais? – kamal

+0

monsieur son ne fonctionne pas s'il vous plaît aider – kamal

+0

voir http://stackoverflow.com/questions/15333022/donot-insert-image-source-code-when-making-vcard/ – lumos