views:

372

answers:

4

Hi all

I need to check in code what Android release version is running currently on target device Can you supply code example

Thanks

+1  A: 

I think this is a duplicate of my own question: ndk version at run time. Short answer: no easy way for a native application to do it (you could however run a Java app and communicate with it to get the version).

Dror Cohen
A: 

can you execute getprop ro.build.version.release shell command on your device ?

zed_0xff
A: 

Hi zed_0xff

This is the answer for your question

I can run this command:

and I get this answer:

getprop ro.build.version.release

getprop ro.build.version.release Eclair #

How this can help me? I need to perform this check in code of java file this should be checked in run time

Do you have example or link for good example !!

ilana
please add this as a comment to your question, or edit your question accordingly. Stackoverflow does not have the typical thread based layout of an discussion board this space is for answers only.
Janusz
A: 

This works

also import the followng: import com.android.phonetests.TEST_INTERFACE; import android.os.Build; import android.app.ActivityThread; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager;

private int GetSDKVersion() { 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; ////this makes the same -> version = Build.VERSION.SDK_INT
            Log.i(LOG_TAG,"[DBG] version: " + version);  

            //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;
}
ilana
Unfortunately, this wasn't working on my 2.1 Nexus One. "com.android.phonetests" seems to not exist.
Steve Pomeroy
Shouldn't you just be getting the value defined in Build.VERSION.SDK_INT instead of querying the targetSdkVersion from some random package?
Steve Pomeroy
thanks, don't know why I didn't use this from the beginning?I simply went a difficult way :-(ThanksIlana
ilana
Steve Pomeroy, I have used package name of my apk file => com.android.phonetests. Now any body who will use my code example should off coarse change it with his/her package name !!
ilana