Reputation: 505
I need to check in code what Android release version is running currently on target device. Can you supply code example?
Upvotes: 15
Views: 21663
Reputation: 91
To get the build version of Android like: 2.2, 2.3.3, 4.0 or 4.0.3 ... use the following code:
String deviceVersion = Build.VERSION.RELEASE;
Upvotes: 9
Reputation: 259
I was looking for this and didn't find a solution - ended up here and I figured it out myself so for anyone out there looking for this:
int SDK_INT = android.os.Build.VERSION.SDK_INT;
this returns os sdk level 7 eclair 8 froyo etc
Upvotes: 25
Reputation: 505
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;
}
Upvotes: -2
Reputation: 33247
can you execute getprop ro.build.version.release
shell command on your device ?
Upvotes: 1
Reputation: 6841
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).
Upvotes: 1