Android Studio调用系统的代码中Build.VERSION.SDK_INT >= Build.VERSION_CODES.xxx

常用来判断sdk版本如下

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    
     
            //包含新的api的代码块
        } else {
    
     
            //包含旧的api的代码块
        }

这里的Build.VERSION.SDK_INT是一个静态变量,代表运行该应用的手机系统的SDK版本,这个值是通过native方法,在Build类加载时获得;Build.VERSION_CODES.M是android sdk中的一个常量,代表的就是不同的SDK版本号

Build.VERSION.SDK_INT,代码:

 public static final int SDK_INT = SystemProperties.getInt("ro.build.version.sdk", 0);

Build.VERSION_CODES.M的M版本号到底是多少,后面的版本号,可以鼠标放到上面+ctrl按键就可以看到如下图:
在这里插入图片描述
原来M版本号是23

从源码里面看到当前有所的sdk版本号:

public static class VERSION_CODES {
    
    
       /**
         * October 2008: The original, first, version of Android.  Yay!
         */
        public static final int BASE = 1;

        /**
         * February 2009: First Android update, officially called 1.1.
         */
        public static final int BASE_1_1 = 2;

        /**
         * May 2009: Android 1.5.
         */
        public static final int CUPCAKE = 3;

                        ......
                        
        public static final int ECLAIR = 5;

        /**
         * December 2009: Android 2.0.1
         */
        public static final int ECLAIR_0_1 = 6;

        /**
         * January 2010: Android 2.1
         */
        public static final int ECLAIR_MR1 = 7;

        /**
         * June 2010: Android 2.2
         */
        public static final int FROYO = 8;
                        ......
        public static final int M = 23;
                        ......
        public static final int N = 24;

        /**
         * N MR1: Nougat++. For more information about this release, see
         * <a href="/about/versions/nougat/android-7.1">Android 7.1 for
         * Developers</a>.
         */
        public static final int N_MR1 = 25;
                        .....
        public static final int O = 26;
                         ......
        public static final int O_MR1 = 27;

                         ......
        public static final int P = 28;

        /**
         * Q.
         * <p>
         * <em>Why? Why, to give you a taste of your future, a preview of things
         * to come. Con permiso, Capitan. The hall is rented, the orchestra
         * engaged. It's now time to see if you can dance.</em>
         */
        public static final int Q = 29;
}

Android系统版本与API级别对应表
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_35091074/article/details/123557081
今日推荐