Reputation: 360
Is there is was to find out what android runtime version is currently used? For example, on android v4.4 you can swipe between dalvik and art and i want to find out this information in runtime.
10x.
Upvotes: 1
Views: 1647
Reputation: 3962
System.getProperty("java.vm.version")
- If ART is used by the system, the returned value will be either "2.0.0" or higher, meaning major versions lower than 2 will be Dalvik. This piece of insight comes from Addressing Garbage Collection (GC) Issues
section of best practices for Verifying App Behavior on the Android Runtime.
// catch only version 2 and not higher
// false for Dalvik, true for current ART, false for any new runtimes
boolean isArt = System.getProperty("java.vm.version").startsWith("2.");
// catch version 2 and above
// false for Dalvik, true for current ART, true for any new runtimes
boolean isArt = false;
try {
isArt = Integer.parseInt(System.getProperty("java.vm.version")
.split(".")[0]) >= 2;
} catch (NumberFormatException e) {
// we suppress the exception and fall back to checking only for current ART
isArt = System.getProperty("java.vm.version").startsWith("2.");
}
Upvotes: 3