Check Android build version : Version « Hardware « Android






Check Android build version

 
/***
  Copyright (c) 2008-2009 CommonsWare, LLC
  
  Licensed under the Apache License, Version 2.0 (the "License"); you may
  not use this file except in compliance with the License. You may obtain
  a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

package app.test;

import java.util.Date;
import java.util.HashMap;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class Test extends Activity {
  private static final String LOG_KEY = "Tagger";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView view = (TextView) findViewById(R.id.test);

    setTag(view, R.id.test, new Date());

    view.setText(getTag(view, R.id.test).toString());
  }

  public void setTag(View v, int key, Object value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
      v.setTag(key, value);
    } else {
      HashMap<Integer, Object> meta = (HashMap<Integer, Object>) v
          .getTag();

      if (meta == null) {
        meta = new HashMap<Integer, Object>();
      }

      meta.put(key, value);
    }
  }

  public Object getTag(View v, int key) {
    Object result = null;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
      result = v.getTag(key);
    } else {
      HashMap<Integer, Object> meta = (HashMap<Integer, Object>) v
          .getTag();

      if (meta == null) {
        meta = new HashMap<Integer, Object>();
      }

      result = meta.get(key);
    }

    return (result);
  }
}
//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView android:id="@+id/test"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />
</LinearLayout>

   
  








Related examples in the same category

1.Honeycomb version
2.Get version information
3.Using VersionedGestureDetector
4.downloads and installs the latest version of our App
5.Get App Version Name
6.Get App Version Code
7.Get Version Name with PackageManager
8.Get Package Version Code and Name
9.Android SDK version
10.Check for intallation, app name, app version, app version code
11.Get version number
12.Utility class providing array to int/long conversion for data received from devices through adb.
13.get Version Name
14.get Version Code
15.Byte value conversion