1

I want to get android os version on my device.

first I try use BUILD.VERSION.RELEASE and BUILD.VERSION.SDK_INT

the release is 6.0.1 sdk_int is 23

but I want to get MARSHMALLOW text.

how to get android os version?

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
hyunwooks
  • 141
  • 3
  • 14
  • 1
    Possible duplicate of [Android:how to find the android version name programmatically?](https://stackoverflow.com/questions/10547818/androidhow-to-find-the-android-version-name-programmatically) – Marat Jul 19 '17 at 03:49
  • did you try my solution? If it worked then please accept the answer and vote up! – JRG Jul 26 '17 at 05:43

1 Answers1

0

Build.VERSION_CODES field name have the OS name so you can use Java Reflection (java.lang.reflect.Field) to get the field name.

https://developer.android.com/reference/android/os/Build.VERSION_CODES.html

    Field[] fields = Build.VERSION_CODES.class.getFields();
    String osName = fields[Build.VERSION.SDK_INT + 1].getName();
    Log.d("TEST", osName);

Sample Log (Note: M is for Marshmallow)

07-18 20:09:08.198 3606-3606/test.atry D/TEST: M
JRG
  • 4,037
  • 3
  • 23
  • 34