tags:

views:

29

answers:

1

Hi:

I am working on an Android application that is supposed to run on Android 1.5 and later devices. I am using RawContacts.CONTENT_URI enumeration for registering a ContentObserver in my application subclass. Now, RawContacts was introduced in Eclair and running this code on Android devices having runtime less than 2.0, gives java.lang.VerifyError. For older devices, I have to use Contacts.CONTENT_URI.

So to fix this, I've put something like the following in my code:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR){
  uri = android.provider.ContactsContract.RawContacts.CONTENT_URI;
}
else{
  uri = android.provider.Contacts.CONTENT_URI;
}

I am still getting java.lang.VerifiyErrors.

How do I setup my code for different runtimes?

+1  A: 

I think you would need to use reflection to get the enumeration you require

http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

As the bytecode will be invalid for devices before 2.0 as it names a class which doesn't exist.

tim_yates