当我们的应用程序针对Gingerbread时,如何整合ICS或Jelly Bean中的功能?如何防止收到的编译错误?
可以说我希望我的应用程序使用类似android.renderscript.ScriptIntrinsicBlend的代码。用户在使用姜饼时无法使用此功能,但是如何为ICS用户启用使用它的选项?为面向Gingerbread的应用程序编写代码时,出现错误。
如何防止这些错误?
最佳答案
您可以执行以下操作:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
// code for ICS and above versions
} else{
// code for phones running an SDK before ICS
}
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html