通過讀取 android.os.Build.VERSION.SDK_INT 獲得操作系統版本 |
package com.example.androidbuildversion; import java.util.Arrays; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.widget.TextView; public class MainActivity extends Activity { final static Integer[] VersionCode = { android.os.Build.VERSION_CODES.BASE, android.os.Build.VERSION_CODES.BASE_1_1, android.os.Build.VERSION_CODES.CUPCAKE, android.os.Build.VERSION_CODES.CUR_DEVELOPMENT, android.os.Build.VERSION_CODES.DONUT, android.os.Build.VERSION_CODES.ECLAIR, android.os.Build.VERSION_CODES.ECLAIR_0_1, android.os.Build.VERSION_CODES.ECLAIR_MR1, android.os.Build.VERSION_CODES.FROYO, android.os.Build.VERSION_CODES.GINGERBREAD, android.os.Build.VERSION_CODES.GINGERBREAD_MR1, android.os.Build.VERSION_CODES.HONEYCOMB, android.os.Build.VERSION_CODES.HONEYCOMB_MR1, android.os.Build.VERSION_CODES.HONEYCOMB_MR2, android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH, android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1, android.os.Build.VERSION_CODES.JELLY_BEAN, android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 }; final static String[] Version = { "BASE - October 2008: The original, first, version of Android", "BASE_1_1 - February 2009: First Android update, officially called 1.1", "CUPCAKE - May 2009: Android 1.5", "CUR_DEVELOPMENT - Magic version number for a current development build", "DONUT - September 2009: Android 1.6", "ECLAIR - November 2009: Android 2.0", "ECLAIR_0_1 - December 2009: Android 2.0.1", "ECLAIR_MR1 - January 2010: Android 2.1", "FROYO - June 2010: Android 2.2", "GINGERBREAD - November 2010: Android 2.3", "GINGERBREAD_MR1 - February 2011: Android 2.3.3", "HONEYCOMB - February 2011: Android 3.0", "HONEYCOMB_MR1 - May 2011: Android 3.1", "HONEYCOMB_MR2 - June 2011: Android 3.2", "ICE_CREAM_SANDWICH - October 2011: Android 4.0", "ICE_CREAM_SANDWICH_MR1 - December 2011: Android 4.0.3", "JELLY_BEAN - June 2012: Android 4.1", "JELLY_BEAN_MR1 - Android 4.2: Moar jelly beans!" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); TextView textVersion = new TextView(this); setContentView(textVersion); int SDKversion = android.os.Build.VERSION.SDK_INT; int matched = Arrays.asList(VersionCode).indexOf((int)SDKversion); if(matched == -1){ textVersion.setText(String.valueOf(SDKversion) + " : " + "unknown!"); }else{ textVersion.setText(String.valueOf(SDKversion) + " : " + Version[matched]); } } }
此留言已被作者移除。
回覆刪除此留言已被作者移除。
回覆刪除