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 6248881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:08:23+00:00 2026-05-24T13:08:23+00:00

I am making a Android application which uses Contacts. The good thing is I

  • 0

I am making a Android application which uses Contacts. The good thing is I managed somehow to make it work with Contacts.Phones as seen on many tutorials. The problem is that Contacts.Phones is deprecated and is replaced by ContactsContract. My application needs to work starting from Android 1.5+.

I need to do some simple operations like:
– query all contacts
– query for a specific contact
– backup all contacts

What is the best way to achieve this, considering I need to have the application working on all versions of android. Do I need to check for current api level on the phone and have 2 code blocks, one before api 5 one after ?

  • 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-24T13:08:23+00:00Added an answer on May 24, 2026 at 1:08 pm

    Here is an optional solution

    int apiVersion = android.os.Build.VERSION.SDK_INT;
    
        if(apiVersion < 5) {
            ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(People.CONTENT_URI, 
                null, null, null, null);
            if (cur.getCount() > 0) {
             while (cur.moveToNext()) {
                 String id = cur.getString(cur.getColumnIndex(People._ID));
                 String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
             }
            }
        } else {
            String columns[] = new String[]{ ContactsContract.Contacts._ID,
                    ContactsContract.Contacts.DISPLAY_NAME };       
            Cursor  cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
                            columns,                
                            null,               
                            null,               
                            ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
            if (cursor.getCount() > 0) {
                 while (cursor.moveToNext()) {
                    long id = Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));   
                    String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).trim();
    
                 }
            }
        }
    

    And here an tutorial to make application Supporting the old and new APIs in the same application this must help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually i am making an android application which is integrated with the Twitter Feeds.
I am making an android application in which I have put 10 images and
I'm making my first Android application and I'm having a problem for which I
I am making an Android application. Since it is so simple, I first thought
I'm making a simple 2d game for the android platform, which works perfectly from
I'm making an ecommerce application on Android and, as it is my first serious
I'm currently making a SMS Application in Android, the following is a code snippet
I am making a Client Server application for my Android phone. I have created
I'm making my first Android application. As a toy problem to learn the system
I'm making a media player application in android where one part of my screen

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.