通常我們都會在AndroidManifest.xml中,添加程式版本名稱和版本資訊,如下圖
In the MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //toast version try { int versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode; String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; String toastString = versionCode + "/" + versionName; Toast.makeText(this, toastString, Toast.LENGTH_SHORT).show(); } catch (NameNotFoundException e) { Toast.makeText(this, "NameNotFoundException", Toast.LENGTH_SHORT).show(); } // }
沒有留言 :
張貼留言