以编程方式检索 Android API 版本

编程入门 行业动态 更新时间:2024-10-27 00:28:00
本文介绍了以编程方式检索 Android API 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有什么办法可以获取手机当前运行的API版本吗?

Is there any way to get the API version that the phone is currently running?

推荐答案

如 Android 文档中所述,手机运行的 SDK 级别(整数)可在:

As described in the Android documentation, the SDK level (integer) the phone is running is available in:

android.os.Build.VERSION.SDK_INT

这个int对应的类在android.os.Build.VERSION_CODES 类.

The class corresponding to this int is in the android.os.Build.VERSION_CODES class.

代码示例:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){ // Do something for lollipop and above versions } else{ // do something for phones running an SDK before lollipop }

编辑:此 SDK_INT 自 Donut (android 1.6/API4) 起可用,因此请确保您的应用程序在使用时不与 Cupcake (android 1.5/API3) 兼容,否则您的应用程序将崩溃(感谢程序员布鲁斯的精确性).

Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).

对应的安卓文档是这里和这里

更多推荐

以编程方式检索 Android API 版本

本文发布于:2023-11-05 15:57:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561266.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   方式   Android   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!