Skip to content

Instantly share code, notes, and snippets.

@noties
Created June 21, 2017 12:49
Show Gist options
  • Save noties/3fc89e99e0fac96e6a508af168175fe7 to your computer and use it in GitHub Desktop.
Save noties/3fc89e99e0fac96e6a508af168175fe7 to your computer and use it in GitHub Desktop.
BuildUtil, util method for checking device's SDK level
package ru.noties.buildutil;
import android.os.Build;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static android.os.Build.VERSION_CODES.BASE;
import static android.os.Build.VERSION_CODES.BASE_1_1;
import static android.os.Build.VERSION_CODES.CUPCAKE;
import static android.os.Build.VERSION_CODES.DONUT;
import static android.os.Build.VERSION_CODES.ECLAIR;
import static android.os.Build.VERSION_CODES.ECLAIR_0_1;
import static android.os.Build.VERSION_CODES.ECLAIR_MR1;
import static android.os.Build.VERSION_CODES.FROYO;
import static android.os.Build.VERSION_CODES.GINGERBREAD;
import static android.os.Build.VERSION_CODES.GINGERBREAD_MR1;
import static android.os.Build.VERSION_CODES.HONEYCOMB;
import static android.os.Build.VERSION_CODES.HONEYCOMB_MR1;
import static android.os.Build.VERSION_CODES.HONEYCOMB_MR2;
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
import static android.os.Build.VERSION_CODES.JELLY_BEAN;
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR2;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.os.Build.VERSION_CODES.LOLLIPOP_MR1;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.N;
import static android.os.Build.VERSION_CODES.N_MR1;
import static android.os.Build.VERSION_CODES.O;
public abstract class BuildUtil {
@IntDef({
BASE, // first version
BASE_1_1, // 1.1
CUPCAKE, // 1.5
DONUT, // 1.6
ECLAIR, // 2.0
ECLAIR_0_1, // 2.0.1
ECLAIR_MR1, // 2.1
FROYO, // 2.2
GINGERBREAD, // 2.3
GINGERBREAD_MR1, // 2.3.3
HONEYCOMB, // 3.0
HONEYCOMB_MR1, // 3.1
HONEYCOMB_MR2, // 3.2
ICE_CREAM_SANDWICH, // 4.0
ICE_CREAM_SANDWICH_MR1, // 4.0.3
JELLY_BEAN, // 4.1
JELLY_BEAN_MR1, // 4.2
JELLY_BEAN_MR2, // 4.3
KITKAT, // 4.4
KITKAT_WATCH, // 4.4W
LOLLIPOP, // 5.0
LOLLIPOP_MR1, // 5.1
M, // 6.0
N, // 7.0
N_MR1, // 7.1
O // 8.0
})
@Retention(RetentionPolicy.SOURCE)
public @interface SdkVersion {
}
public static boolean canIUse(@SdkVersion int sdkVersion) {
return Build.VERSION.SDK_INT >= sdkVersion;
}
private BuildUtil() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment