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);
}
2
  • You could make a utility method that does the translation when given a VERSION.SDK. Commented Mar 1, 2013 at 6:58
  • Here is a good answer by Kevin Grant: stackoverflow.com/a/13258693/488489 Commented Mar 1, 2013 at 7:05

3 Answers 3

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think you can use VERSION.RELEASE field instead.

tv.setText(android.os.Build.VERSION.RELEASE + "");

Comments

0

Try using

TextView tv = (TextView) findViewById(R.id.display);
tv.setText(String.valueOf(android.os.Build.VERSION.RELEASE));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.