Detect Android N version code

后端 未结 4 1783
既然无缘
既然无缘 2021-02-06 03:12

Is it possible to detect if an user is running Android N?

I have a Nexus 6 with the Android N Developer Preview. If I try to get the build version with Build.VERSI

4条回答
  •  粉色の甜心
    2021-02-06 03:17

    Quoting myself:

    Following the approach that Google used for the M Developer Preview, you can check Build.VERSION.CODENAME instead:

    public static boolean iCanHazN() {
      return("N".equals(Build.VERSION.CODENAME));
    }
    

    I haven't looked at Build.VERSION.RELEASE, as suggested by zgc7009's comment, though that too may be a possibility.

    Also, if you are reading this from the far future, where Android N has shipped in final form, you should be able to use Build.VERSION.SDK_INT and Build.VERSION_CODES.N. The above hack is due to the idiosyncrasies of how Google handles these developer previews.

提交回复
热议问题