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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:53:12+00:00 2026-05-23T07:53:12+00:00

I have the following piece of code in my Android application that looks up

  • 0

I have the following piece of code in my Android application that looks up a contacts ID, I have just changed the target from 1.5 to 2.2 but with a min SDK of 3 (1.5) so that I can use the ContactsContract Uri in 2.2 and the People Uri in 1.5.

However the code leads to the following error when run on 1.5 devices:

07-27 15:02:53.382: WARN/dalvikvm(12656): VFY: unable to resolve static field 25 (CONTENT_URI) in Landroid/provider/ContactsContract$Contacts;

From google I have garnered that I need to use reflection in this case to allow the application run on both versions of Android?

I have seen example’s of how to use reflection to use methods of multiple/different versions but how can I use it in mycase where I want to use the ContactsContract Uri?

Here is my code:


findViewById(R.id.contactimage).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {

                    String sdk = android.os.Build.VERSION.SDK;
                    Uri contactUri;
                    Log.d("CDA", "Contact ID Button pressed = " + contactId);
                    if(sdk.equals("8")){
                        contactUri = ContentUris.withAppendedId
                        (ContactsContract.Contacts.CONTENT_URI, contactId);

                        Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
                        startActivity(intent);

                    }
                    else{
                    contactUri = ContentUris.withAppendedId
                    (People.CONTENT_URI, contactId);

                    Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
                    startActivity(intent);
                    }

                    dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.FLAG_SOFT_KEYBOARD));
                    dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
                }
        });

EDIT:

Here is an example of how its done:

private static Uri CONTENT_URI=null;
private static String NAME_URI=null;
private static String ID_URI=null;
private static String NUMBER_URI = null;
private static Uri PHONE_LOOKUP = null;
static int sdk;
 static {
     sdk=new Integer(Build.VERSION.SDK).intValue();

     if (sdk>=5) {
     try {
     Class clazz=Class.forName("android.provider.ContactsContract$CommonDataKinds$Phone");
     Class clazz_phonelookup=Class.forName("android.provider.ContactsContract$PhoneLookup");

     NAME_URI=(String)clazz.getField("DISPLAY_NAME").get(clazz);
     ID_URI=(String)clazz.getField("_ID").get(clazz);

     NUMBER_URI=(String)clazz.getField("NUMBER").get(clazz);
     PHONE_LOOKUP =(Uri)clazz_phonelookup.getField("CONTENT_FILTER_URI").get(clazz);


     }
     catch (Throwable t) {
     Log.e("reflection", "Exception when determining CONTENT_URI", t);
     }
     }
     else {
     CONTENT_URI=Contacts.People.CONTENT_URI;

     NAME_URI=People.NAME;
     ID_URI=People._ID;

     NUMBER_URI=People.NUMBER;
     PHONE_LOOKUP = null;

     }
     }
  • 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-23T07:53:12+00:00Added an answer on May 23, 2026 at 7:53 am

    This demo from the documentation defines a parent class for two different SDK-specific classes that work for API levels 3/4 and API levels 5+.

    This helped me understand the differences between Contacts and ContactsContract, and allows for usage of both implicitly by getting the OS API level in the wrapper class.

    http://developer.android.com/resources/samples/BusinessCard/index.html

    Hope this helps!

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

Sidebar

Related Questions

I have the following piece of code taken from the PHP manual on the
I have the following piece of code from a book. There is this function
I have following piece of code which tries to load an XML file from
I have following piece of code from my Backbone project: App.Controllers.Test = Backbone.Router.extend({ routes:
I have the following piece of code its working fine,no issues but i am
I have the following piece of code in my Spring MVC application: @RequestMapping(value =
I have the following piece of code in a file that I opened in
I have a piece of code that works on most browsers except the Android
I have the following piece of code. It all works but I'm having a
I have the following piece of code ( Prototype ): $('table_cell_id') That cell contains

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.