Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect java version on Android phone at runtime

Is there way to programatically from an Android app detect the version of Java that the phone supports?

i.e. to see if the phone can run java 8 bytecode for instance?

like image 908
zaifrun Avatar asked Oct 01 '18 10:10

zaifrun


People also ask

How do I check my Java version on my phone?

There is no such thing called Java version in android device. When you compile Java code to build android application, it is converted into DEX format from class file and it runs in Dalvik Virtual machine or Android Runtime (ART).

How do I check my Java version on Android?

If in About Android Studio you only see the build number, go to Preferences. From the menu: File > Settings ... (Settings dialog appears) ... Appearance & Behaviour > System Settings > Updates. Here, both the current version and the build number are shown.

What version of Java does Android run?

Android Gradle plugin 3.0. 0 and later support all Java 7 language features and a subset of Java 8 language features that vary by platform version.


1 Answers

There is no such thing called Java version in android device. When you compile Java code to build android application, it is converted into DEX format from class file and it runs in Dalvik Virtual machine or Android Runtime (ART). The conversion of Java code to DEX format happens in compile time, so it is not required to have latest Java to interpret the DEX file in the runtime.

But you need to note that all class definations of Java may not exist in an android device. For example, the method java.util.Base64.getDecoder() is available as of JDK 1.8, and it can be used in android API level 17 or above. But code with lambda expression (JDK 1.8 feature) can run in lower API levels too.

like image 65
Nabin Bhandari Avatar answered Sep 25 '22 08:09

Nabin Bhandari