Using new sdk methods on devices running older sdks?

by Mark Murphy » Tue, 22 Dec 2009 01:47:43 GMT


Sponsored Links
 


I wouldn't do:

if (Build.VERSION.SDK.equals("5")) {

Instead, parse it to an integer and do a >=5 comparison. After all, most
DROIDs are now on API 6 (i.e., Android 2.0.1). And, once you drop older
SDK support, you can use SDK_INT and skip the parse step.

If you are going to make the request a lot, you might consider having
your two implementations extend a common abstract class or implement a
common interface. Then, you can make the determination of which one to
use once and hold onto that object, calling it by the common interface
as needed.

Otherwise, the notion of "if I don't load the class, there will be no
harm in it referencing newer API capabilities" is sound.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to Android Development_ Version 2.8
Available!

--



Other Threads

1. Clearing Touch Mode?

Is there a way in code to switch an application from Touch Mode to
Keyboard mode, or is this handled only via pressed on the screen or
keyboard?
--~--~---------~--~----~------------~-------~--~----~

2. write_sms and send_sms permissions

Why does Android need to have 2 distinct permissions?

write_sms
and
send_sms
--~--~---------~--~----~------------~-------~--~----~

3. How to get Android local IP(192.168.1.18)? not 127.0.0.1..

4. Logging URL typed in the browser

5. prepareAsync called in state 1 error

6. Is Theme.Light supported in 1.0?

7. Saving a Serialized Object