Creating vCard file programmatically in android
<p>I am using the following code to read contacts and create a vcard file. </p>

<pre><code>            String lookupKey = cur.getString(cur.getColumnIndex(Contacts.LOOKUP_KEY));
            Uri uri=Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);


            try {
                fd = cr.openAssetFileDescriptor(uri, "r");
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
            try {
                fis = fd.createInputStream();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            byte[] buf = new byte[(int)fd.getDeclaredLength()];
            try {
                if (0 &lt; fis.read(buf))
                {
                    vCard = new String(buf);
                    writer.write(vCard);
                    writer.write("\n");
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
</code></pre>

<p>But while going through the list of contacts, I get the error:</p>

<blockquote>
  <p>ERROR/MemoryFile(284):
  MemoryFile.finalize() called while
  ashmem still open.</p>
</blockquote>

<p>And my generated .vcf file is missing some contacts and also does not end properly.</p>

<p>Can someone please tell me what is wrong with my code.</p>
