Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6788641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:30:34+00:00 2026-05-26T17:30:34+00:00

I am trying to read Android device contacts in VCard format using Android Api.

  • 0

I am trying to read Android device contacts in VCard format using Android Api.
i found one link for the same:
Android contatcs vcard API

and trying to write the same code but its not working, as I am not able to get the lookupkey:

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);  
int num = cur.getCount();  // I get 2 , as there are two contacts

String lookupKey = cur.getString(cur.getColumnIndex(Contacts.LOOKUP_KEY));
// The above line gives error : android.database.CursorIndexOutOfBoundsException:
//  Index -1 requested, with a size of 2

Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
AssetFileDescriptor fd = resolver.openAssetFileDescriptor(uri, "r");
FileInputStream fis = fd.createInputStream();
    byte[] b = new byte[(int)fd.getDeclaredLength()];
fis.read(b);
String vCard = new String(b);
sb.append(vCard);

Can anyone please tell me how to get the lookupkey for the above code or there is any other way we can get contacts VCard format using Android api.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:30:35+00:00Added an answer on May 26, 2026 at 5:30 pm

    — Edit 2 —

    It looks like you are not doing cur.moveToFirst() before reading cursor, so you are getting exceptiion. try look into android.database.CursorIndexOutOfBoundsException: Index -1 requested which describes the same problem.

    — Edited answer —

    LookUpKey in the code is for a specific contact. The conde example you are using is to get the vcard for a specific contact. you have to loop though the available contacts and inside you can put the code you have to get it working. You can get look up key from contact contract.

    apart from that, you should consider following a general solution:

    1. Please add error that you got in logcat
    2. have you added contact permission in application manifest to allow application to read contacts?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new for android development. I am trying read and write contacts to
I 'm trying to read and display contacts from phone book in android. My
I'm Trying to Write Logs to Custom Log.txt File on Android File using this
I'm trying to read all the contacts using RawContacts.entityIterator but I'm seeing this error:
I'm trying to send an image using a Java server to my Android device
Trying to read an RSS and select information using Linq but can't seem to
I've been trying to get a handle on Dialogs. I read the android dev
Trying to read an utf-8 encoded file in android... InputStreamReader reader = new InputStreamReader(assets.open(data.txt),
I am trying to read Android source code to learn about binder, but I
I'm trying to create an android context menu (the one that pops-up when you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.