Demo:
1)MainActivity.java:
3) Download this code Click Here
1)MainActivity.java:
package
com.venky.checkrunningandroidversion;
import
android.app.Activity;
import
android.os.Bundle;
import
android.widget.TextView;
public class MainActivity extends Activity {
TextView tvApiVersion;
TextView tvApiVersionName;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvApiVersion = (TextView)
findViewById(R.id.tvApiVersion);
tvApiVersionName = (TextView)
findViewById(R.id.tvApiVersionName);
int
currentApiVersion = android.os.Build.VERSION.SDK_INT;
tvApiVersion.setText("Current
API version => " + currentApiVersion);
if
(currentApiVersion == android.os.Build.VERSION_CODES.DONUT) {
tvApiVersionName.setText("Current
API Version Name => DONUT");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.ECLAIR) {
tvApiVersionName.setText("Current
API Version Name => ECLAIR");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.ECLAIR_0_1) {
tvApiVersionName.setText("Current
API Version Name => ECLAIR_0_1");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.ECLAIR_MR1) {
tvApiVersionName.setText("Current
API Version Name => ECLAIR_MR1");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.FROYO) {
tvApiVersionName.setText("Current
API Version Name => FROYO");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.GINGERBREAD) {
tvApiVersionName.setText("Current
API Version Name => GINGERBREAD");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
tvApiVersionName
.setText("Current
API Version Name => GINGERBREAD_MR1");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.HONEYCOMB)
{
tvApiVersionName.setText("Current
API Version Name => HONEYCOMB");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.HONEYCOMB_MR1)
{
tvApiVersionName
.setText("Current
API Version Name => HONEYCOMB_MR1");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.HONEYCOMB_MR2)
{
tvApiVersionName
.setText("Current
API Version Name => HONEYCOMB_MR2");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
tvApiVersionName
.setText("Current
API Version Name => ICE_CREAM_SANDWICH");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
{
tvApiVersionName
.setText("Current
API Version => ICE_CREAM_SANDWICH_MR1");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.JELLY_BEAN) {
tvApiVersionName.setText("Current
API Version => JELLY_BEAN");
} else if
(currentApiVersion == android.os.Build.VERSION_CODES.JELLY_BEAN_MR1)
{
tvApiVersionName.setText("Current
API Version => JELLY_BEAN_MR1");
}
}
}
2)xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5F04B4"
android:orientation="vertical"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/tvApiVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:textColor="#ffffff"
android:textSize="15dp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/tvApiVersionName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#ffffff"
android:textSize="15dp"
android:textStyle="bold"
/>
</LinearLayout>
3) Download this code Click Here
No comments:
Post a Comment