2

In my app I am trying to display the Android version of the users current device as a textview however I have used the os.build.version.sdk and when I use that only the sdk code shows e.g 17 for Android 4.0.4 and I was trying get the Android version to show so is there a way to make an if or else statement to change the 17 into 4.0.4 at runtime. I have attached my java class below.

{
    TextView tv = (TextView) findViewById(R.id.display);
    tv.setText(android.os.Build.VERSION.SDK);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

1

To display the Android release number, I would suggest to use android.os.Build.VERSION.RELEASE: http://developer.android.com/reference/android/os/Build.VERSION.html

{
    TextView tv = (TextView) findViewById(R.id.display);
    tv.setText(android.os.Build.VERSION.RELEASE);
}
Axel Cateland
  • 125
  • 1
  • 8
0

I think you can use VERSION.RELEASE field instead.

tv.setText(android.os.Build.VERSION.RELEASE + "");
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
0

Try using

TextView tv = (TextView) findViewById(R.id.display);
tv.setText(String.valueOf(android.os.Build.VERSION.RELEASE));
Sankar V
  • 4,794
  • 3
  • 38
  • 56