检查Android版本 [英] Checking Android version

查看:91
本文介绍了检查Android版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/3423754/retrieving-android-api-version-programmatically">Retrieving Android的API版本编程

我需要的,如果在运行该应用的API级的电话是14,它是机器人4.0以上(实施例API levcel 15)然后startActivity ...否则,如果API级别低于14(实施例13),然后startActivity ..

I need if the phone running the app api level is 14 which is android 4.0 or more ( example api levcel 15 ) then startActivity ... else if the api level is lower than 14 ( example 13 ), then startActivity ...

                String AndroidVersion = android.os.Build.VERSION.RELEASE;
                if ( AndroidVersion == 4.0 ) {
                    Intent start = new Intent(S.this, Menu.class);
                    startActivity(start);                       
                }
                else {
                    Intent startt = new Intent(S.this, Menu2.class);
                    startActivity(startt);
                }

什么错?

推荐答案

使用 SDK_INT ,而不是发布。所以,你的code看起来像:

Use SDK_INT instead of RELEASE. So your code would look like:

Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
  intent = new Intent(S.this, Menu.class);
} else {
  intent = new Intent(S.this, Menu2.class);
}

try {
  startActivity( intent );
} catch( Exception e ) {
  e.printStackTrace();
}

所有SDK codeS的这里列出。心中总是从startActivity捉可能的例外();它不会伤害(即使是在您的应用程序 - 你可以随时忘记添加活动,而开发的体现),是一个很好的习惯,prevent距离,同时提供在日志中一些有用的东西崩溃您的应用程序

all SDK codes are listed here. Mind to always catch possible exception from startActivity(); It won't hurt (even within your app - you can always forget to add activity to Manifest while developing), is a good habit and prevent your app from crashing while providing something useful in the logs

这篇关于检查Android版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆