1

我正在使用此代码制作 Vcard,现在我想在我的 vcard 中不要插入图像代码,所有其他内容都将添加到 vcard 中,我是如何做到的......我正在使用这个

         String VCard = "";

         Cursor phones = getContentResolver().query(android.provider.ContactsContract.Contacts.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();
        }
4

1 回答 1

1
    String lookupKey = phones.getString(phones
    .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri vcardUri = ContactsContract.Contacts.CONTENT_VCARD_URI
    .buildUpon()
    .appendQueryParameter("nophoto", String.valueOf(true))
    .build();
Uri uri = Uri.withAppendedPath(vcardUri, lookupKey);

我再次修改它,在for循环中使用

于 2013-03-11T07:20:51.397 回答