在api级别8制作vcard时,不要插入图像源代码

时间:2013-03-11 07:09:40

标签: android vcard

我正在使用此代码制作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();
        }

1 个答案:

答案 0 :(得分: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循环