Android API Version programmatically
You can get it by calling Build.VERSION.SDK
.
From 1.6 on, you should use Build.VERSION.SDK_INT
instead
because Build.VERSION.SDK
is deprecated.
How to find the Android version name programmatically?
As suggested earlier, reflection seems to be the key to this question. The StringBuilder and extra formatting is not required, it was added only to illustrate usage.
import java.lang.reflect.Field;
...
StringBuilder builder = new StringBuilder();
builder.append("android : ").append(Build.VERSION.RELEASE);
Field[] fields = Build.VERSION_CODES.class.getFields();
for (Field field : fields) {
String fieldName = field.getName();
int fieldValue = -1;
try {
fieldValue = field.getInt(new Object());
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
if (fieldValue == Build.VERSION.SDK_INT) {
builder.append(" : ").append(fieldName).append(" : ");
builder.append("sdk=").append(fieldValue);
}
}
Log.d(LOG_TAG, "OS: " + builder.toString());
On my 4.1 emulator, I get this output:
D/MainActivity( 1551): OS: android : 4.1.1 : JELLY_BEAN : sdk=16
Enjoy!
How can I check the system version of Android?
Check android.os.Build.VERSION
.
CODENAME
: The current development codename, or the string "REL" if this is a release build.INCREMENTAL
: The internal value used by the underlying source control to represent this build.RELEASE
: The user-visible version string.
Retrieving API version programmatically using Context
You can use Build.VERSION.RELEASE
to get Android version as displayed in About Phone information
How to get the Android API version at runtime from Delphi Rio?
It can be done this way:
uses
Androidapi.JNI.Os;
...
if TJBuild_VERSION.JavaClass.SDK_INT > SomeValue then
Where the value of SomeValue is the API level you want to check against.
Related Topics
How to Get Extra Data from Intent on Android
Making Textview Scrollable on Android
Error in Launching Avd With Amd Processor
How to Connect to a Specific Wi-Fi Network in Android Programmatically
How to Change an Application Icon Programmatically in Android
How to Get Current Time and Date in Android
How to Update Recyclerview Adapter Data
Simple Android Grid Example Using Recyclerview With Gridlayoutmanager (Like the Old Gridview)
How to Install Google Play Services in a Genymotion Vm (With No Drag and Drop Support)
How to Use Recyclerview Inside Nestedscrollview
Retrieving Android API Version Programmatically
How to Go Back to Previous Page If Back Button Is Pressed in Webview
Android Studio 3.5 Refactor Issue
How to Handle Screen Orientation Change When Progress Dialog and Background Thread Active