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));
                            }
                    });

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to