Discussion:
Import Contacts from .vcf file in Android 2.1
Prateek Jain
2010-11-26 05:11:40 UTC
Permalink
Hi All,

I am able to retrieve all contacts from android in .vcf file using
following code.

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,
null, null, null);
String lookupKey =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri =
Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,
lookupKey);
System.out.println("The value is " +
cr.getType(uri));
AssetFileDescriptor fd =
this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();


I don't know how to use this .vcf file to import all these contacts
using code. The .vcf file contains all the details of all contacts
including photos etc.

Cheers, Prateek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Jens
2010-11-28 15:03:27 UTC
Permalink
Afaik there is no "standard" way to insert contacts from a vcf file
into the contacts provider. The entire package that deals with vCards,
android.pim.vcard is hidden in the SDK and not available unless you're
a big fan of abusing Java Reflection - in short, you should lift the
parser from the android source tree and package it in your app.

If you want to browse the code it uses for serializing and parsing
vCards (both 2.1 and 3.0) it's available here.
http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/android/pim/vcard/
Post by Prateek Jain
Hi All,
I am able to retrieve all contacts from android in .vcf file using
following code.
ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,
null, null, null);
String lookupKey =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
                        Uri uri =
Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,
lookupKey);
                        System.out.println("The value is " +
cr.getType(uri));
                        AssetFileDescriptor fd =
this.getContentResolver().openAssetFileDescriptor(uri, "r");
                        FileInputStream fis = fd.createInputStream();
I don't know how to use this .vcf file to import all these contacts
using code. The .vcf file contains all the details of all contacts
including photos etc.
Cheers, Prateek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Prateek Jain
2010-11-29 06:20:20 UTC
Permalink
Thanks Jens for the reply.

I am afraid why Android has kept the import contacts api hidden though
to export contacts in vcf format is available.

I think I have to go hard way by packaging android source code in the
app until I find a better solution for this.

Thanks,
Prateek
Post by Jens
Afaik there is no "standard" way to insert contacts from a vcf file
into the contacts provider. The entire package that deals with vCards,
android.pim.vcard is hidden in the SDK and not available unless you're
a big fan of abusing Java Reflection - in short, you should lift the
parser from the android source tree and package it in your app.
If you want to browse the code it uses for serializing and parsing
vCards (both 2.1 and 3.0) it's available here.http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/java/androi...
Post by Prateek Jain
Hi All,
I am able to retrieve all contacts from android in .vcf file using
following code.
ContentResolver cr = getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,
null, null, null);
String lookupKey =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
                        Uri uri =
Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,
lookupKey);
                        System.out.println("The value is " +
cr.getType(uri));
                        AssetFileDescriptor fd =
this.getContentResolver().openAssetFileDescriptor(uri, "r");
                        FileInputStream fis = fd.createInputStream();
I don't know how to use this .vcf file to import all these contacts
using code. The .vcf file contains all the details of all contacts
including photos etc.
Cheers, Prateek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
SamuelSpring
2012-05-20 08:12:22 UTC
Permalink
Hi there. Was there any solution for this? 'Cause I have a same problem.
Post by Prateek Jain
Hi All,
I am able to retrieve all contacts from android in .vcf file using
following code.
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null,
null, null, null);
String lookupKey =
cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri =
Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI,
lookupKey);
System.out.println("The value is " +
cr.getType(uri));
AssetFileDescriptor fd =
this.getContentResolver().openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
I don't know how to use this .vcf file to import all these contacts
using code. The .vcf file contains all the details of all contacts
including photos etc.
Cheers, Prateek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Jason Teagle
2012-05-20 08:23:23 UTC
Permalink
Post by Prateek Jain
I don't know how to use this .vcf file to import all these contacts
using code. The .vcf file contains all the details of all contacts
including photos etc.
Please try to use search engines to find what you need before asking. A
Google search took 5 seconds:

http://en.wikipedia.org/wiki/VCard

It lists the applicable RFC files.


And the same question asked by the OP at the same time on StackOverflow:

http://stackoverflow.com/questions/4144193/import-contacts-from-vcf-file-in-android-2-1
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
asheesh arya
2012-05-21 05:13:18 UTC
Permalink
juzz go through this link
http://eagle.phys.utk.edu/guidry/android/readContacts.html
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Loading...