如果我正确阅读了您的问题,那么这将允许您将应用程序安装在 7 级设备上
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="12" />
对于开发,您可以将其设置为您想要的任何目标,即您的项目目标可以是 SDK 4.0,但您的清单目标可以是 1.5 (android:targetSdkVersion="3"),反之亦然。Eclipse 会给你一个警告,但你可以为任何目标开发并将你的清单设置为任何目标,只要你考虑到后果。
您可能知道在您的代码中需要做一些工作,以确保应用程序在尝试调用第 7 级不存在的方法时不会崩溃。如果您需要,我已经编写了代码来处理它例子。
编辑:
一个对我有用的例子。
/**
* Get the current SDK version as an integer. If we are using 1.5 the SDK is
* returned as a String so using the Build.VERSION.SDK_INT method will cause
* the application to crash. This method will return 3 if the version is 1.5
* and will return the proper result for Build.VERSION.SDK_INT if that
* method is available.
*
* @return
*/
public static int getSdkInt() {
if (Build.VERSION.RELEASE.startsWith("1.5"))
return 3;
try {
return YourInternalClass.getSdkIntInternal();
} catch (VerifyError e) {
Log.e(TAG, e.toString());
return 3;
}
}
您应该调用内部类中可能不存在的任何方法,以便在调用该方法之前它不会加载。
private static class YourInternalClass {
private static int getSdkIntInternal() {
return Build.VERSION.SDK_INT;
}
}
现在您可以检查 SDK 版本。如果您有任何仅存在于大于 7 的包中的方法,请将这些方法放在内部类中。那么你可以做
if(TheClassYouPutThisMethodIn.getSDKInt() >= 12)
YourInternalClass.yourLevel12Method();
我确信可能有更好的方法来做到这一点(我希望有人可以发布它)但它对我来说非常有用。我的应用程序使用 SDK 13 中的方法在 3 级手机上安全运行。
希望这可以帮助。