机器人如何检查版本机器人、版本

2023-09-07 02:43:47 作者:血屠殺手

我做了我的应用程序在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;
}