Running an Android 2.x application in a 1.x emulator
I need to force an Android project created in Eclipse for the 2.0 platform to run on the 1.开发者_JAVA技巧5 AVD (emulator). This is due to the fact that I'm writing an app that will support both the Contacts API and the ContactsContract API.
Does anyone know the magic word to make this happen?
If we are really talking about an Android project (folders with .java source files and all the XML files required and so on) then just right click the project folder and hit Properties
. In the properties window select the Android
section in the left pane. Now just select the project build target you want to use and hit Apply
.
EDIT: If you want to provide backwards compatibility for certain features then simply check for the SDK version and decide what to do upon a certain version SDK version.
int sdk = new Integer(Build.VERSION.SDK).intValue();
if(sdk >= 5) {
// do whatever you need
}
else {
// do whatever else you need
}
Check out the answers to this question: How to use contacts API for Android 1.x and 2.x simultaneously?
Conditional Classloading is what you're looking for, I think. In that case, I think you would configure your project as a 1.x project, and it should build and run on 1.x, and then if it detected a 2.x phone, it would use the newer API.
精彩评论