Seeking the Proper Level
if (sdk< 5 ) {
return(new OldMobileContacts());
}
return(new NewMobileContacts());
}
The buildBridge() method looks at the SDK value and chooses an
implementation to use. The sendSMS() message takes the Cursor and field
name from the bridge and pours that information into the
AlertDialog.Builder.
You can now compile and run LunchList on both Android 2.x and Android
1.x.
Extra Credit
Here are some things you can try beyond those step-by-step instructions:
- Rather than determining which API to use by looking at the SDK
version, check to see if the ContactsContract class exists, since that
class does not exist on Android 1.x.
- Experiment with using pure reflection to get at the Uri for the
content provider based on the version of Android the code is
running on.
Further Reading
More information about supporting multiple API levels in Android is found
in the "Handling Platform Changes" chapter of The Busy Coder's Guide to
Android Development.