-4

I want to print the android version of the phone by using android.os.build.version.release. But I cant able to print that on the main activity.I have created a text-field about the version.

Operating System : ( now I want to print the details here).

I have just started android programming so I am a noob so please help me.

CodeWalker
  • 2,281
  • 4
  • 23
  • 50
user2675040
  • 79
  • 2
  • 7
  • 3
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. – 2Dee Jan 29 '15 at 13:34
  • 1
    Please let some light from your code hit our eyes – CodeWalker Jan 29 '15 at 13:37
  • possible duplicate of [How to get the build/version number of your Android application?](http://stackoverflow.com/questions/4616095/how-to-get-the-build-version-number-of-your-android-application) – Shabbir Dhangot Jan 29 '15 at 13:43

3 Answers3

0

you should share some code fragments...

Usually you get the data you want with this:

Build.VERSION.RELEASE

This will print e.g. "4.4.3" wherever you set the text (e.g. editText.setText(Build.VERSION.RELEASE).

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
Tobias Amon
  • 275
  • 3
  • 5
0

Consider tv as your TextView. Build.VERSION.RELEASE will return a user-visible version string e.g. "2.3.3".

String osVersion = "Operating System : "+Build.VERSION.RELEASE;
tv.setText(osVersion);
Hemanth
  • 2,717
  • 2
  • 21
  • 29
0

Hope this helps!
MainActivity,java

package com.example.versioninfo;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView versionInfo = (TextView) findViewById(R.id.verInfo);
    versionInfo.setText("Android "+Build.VERSION.RELEASE);

    }
}



activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.versioninfo.MainActivity" >

<TextView
    android:id="@+id/verInfo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="150dp" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/verInfo"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="27dp"
    android:layout_marginLeft="110dp"
    android:text="Operating System : " />

</RelativeLayout>
CodeWalker
  • 2,281
  • 4
  • 23
  • 50