机器人如何检查版本 [英] Android How to check Version

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

问题描述

我做了我的应用程序在2.2环境中,当我安装我的APK在旧版本我收到解析错误。有什么可能性,以显示自己的信息,而不是解析错误消息。按我看来,这是不是。因为我用Google搜索这个问题没有什么暗示这个话题。如果有人知道请分享等也可以理解,如果他们想显示这种消息。谢谢andvance。

I did my application in 2.2 environment, when i install my apk in older version i am getting parser error. is there anything possibility to display our own message instead parser error message. As per my opinion it is not. Because i googled about this issue there is nothing hints about this topic. if anyone knows pls share and others can also understand if they want to display this kind of message. Thanks in andvance.

推荐答案

做这样的事

private int GetVersion()
{
    int version = 0;
    IPackageManager pm = ActivityThread.getPackageManager();
    try
    {
        //returns a ref to my application according to its application name
        ApplicationInfo applicationInfo = pm.getApplicationInfo("com.android.phonetests", 0);

        if (applicationInfo != null) 
        {           
            version = applicationInfo.targetSdkVersion; 

            //2 is 5
            //2.01 6 (Donut - 2.01)
            //2.2  7 (Eclair - 2.2) currently it is Eclair_MR1 (Major Release)                  
            switch (version) 
            {                           
                case Build.VERSION_CODES.ECLAIR_MR1:
                Log.i(LOG_TAG,"[DBG] version: ECLAIR");//2.2  7 (Eclair - 2.2) currently it is Eclair_MR1 (Major Release)
                break;
                case Build.VERSION_CODES.DONUT:
                Log.i(LOG_TAG,"[DBG] version: DONUT");//2.01 6 (Donut - 2.01)
                break;
            }
        }
    } 
    catch (android.os.RemoteException e){}      
    return version;
}

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

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