I want to check if the android version is above ICS:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){

I have a code error,

    ICE_CREAM_SANDWICH cannot resolved or it is not a field

But I can read here

http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

this is the correct way, where is the mistake?

Edit after Andy Res answer

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

But if I check Project->properties->Android, ICS doesn't appear, from Android 3.1 to Android 4.1. I suppose this is the error, how can I solve it?

有帮助吗?

解决方案

But if I check Project->properties->Android, ICS doesn't appear, from Android 3.1 to Android 4.1. I suppose this is the error, how can I solve it?

Use the SDK Manager and download the SDK(s) that you want. They will then appear in the list for you to set your build target.

其他提示

Simply use this

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 14){

Make sure the project build target is Android 4.0 or higher.

(Assuming you use Eclipse, you would do this by: Right clicking on the project -> Properties -> From the left menu click on Android -> then choose the target)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top