Tim Jowers wrote:
> Is there an API to determine the phone's version of Android? For now,
> I'm using try-catch. Sucky but works.
android.os.Build.VERSION.SDK. Or, if you're only worrying about 1.6 and
newer, use SDK_INT instead of SDK.
> Also, my 2.0 built APK does not run on my G1 phone. Maybe it's
> something I've done but I haven't dug into it. Maybe that's what you
> meant by "intelligent" class loading.... do you mean Class.forName()
> or Class.loadClass() or whatever its called instead of import
> blahblh;?
Well, you'll need to look at your stack trace. You can get that from adb
logcat, DDMS, or the DDMS perspective in Eclipse. IIRC, using a class
that references 2.0 APIs in a 1.5/1.6 environment will give you a
VerifyError.
Using Class.forName() is one technique to create an application that can
use ContactsContract. Or, do something like this:
abstract class ContactsAdapterBridge {
abstract ListAdapter buildNameAdapter(Activity a);
abstract ListAdapter buildPhonesAdapter(Activity a);
abstract ListAdapter buildEmailAdapter(Activity a);
public static final ContactsAdapterBridge INSTANCE=buildBridge();
private static ContactsAdapterBridge buildBridge() {
int sdk=new Integer(Build.VERSION.SDK).intValue();
if (sdk<5) {
return(new OldContactsAdapterBridge());
}
return(new NewContactsAdapterBridge());
}
}
This is a fragment of a sample that I'll be uploading to github tomorrow
sometime (I hope). NewContactsAdapterBridge uses ContactsContract;
OldContactsAdapterBridge uses Contacts. So long as you don't try
*loading* a class that uses 2.0 APIs, you won't get a VerifyError. The
2.0-referencing class can still be in the APK, though.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android Training in US: 11-15 January 2010: http://onlc.com
--
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