Android獲取手機(jī)型號(hào)/系統(tǒng)版本號(hào)/App版本號(hào)等信息實(shí)例講解
更新時(shí)間:2013年06月17日 17:08:52 作者:
本示例獲得手機(jī)型號(hào),系統(tǒng)版本,App版本號(hào)等信息,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈
MainActivity如下:
package cn.testgethandsetinfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
/**
* Demo描述:
* 獲得手機(jī)型號(hào),系統(tǒng)版本,App版本號(hào)等信息
*/
public class MainActivity extends Activity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mTextView=(TextView) findViewById(R.id.textView);
mTextView.setText(getHandSetInfo());
}
private String getHandSetInfo(){
String handSetInfo=
"手機(jī)型號(hào):" + android.os.Build.MODEL +
",SDK版本:" + android.os.Build.VERSION.SDK +
",系統(tǒng)版本:" + android.os.Build.VERSION.RELEASE+
",軟件版本:"+getAppVersionName(MainActivity.this);
return handSetInfo;
}
//獲取當(dāng)前版本號(hào)
private String getAppVersionName(Context context) {
String versionName = "";
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo("cn.testgethandsetinfo", 0);
versionName = packageInfo.versionName;
if (TextUtils.isEmpty(versionName)) {
return "";
}
} catch (Exception e) {
e.printStackTrace();
}
return versionName;
}
}
main.xml如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_centerInParent="true"
/>
</RelativeLayout>
復(fù)制代碼 代碼如下:
package cn.testgethandsetinfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
/**
* Demo描述:
* 獲得手機(jī)型號(hào),系統(tǒng)版本,App版本號(hào)等信息
*/
public class MainActivity extends Activity {
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mTextView=(TextView) findViewById(R.id.textView);
mTextView.setText(getHandSetInfo());
}
private String getHandSetInfo(){
String handSetInfo=
"手機(jī)型號(hào):" + android.os.Build.MODEL +
",SDK版本:" + android.os.Build.VERSION.SDK +
",系統(tǒng)版本:" + android.os.Build.VERSION.RELEASE+
",軟件版本:"+getAppVersionName(MainActivity.this);
return handSetInfo;
}
//獲取當(dāng)前版本號(hào)
private String getAppVersionName(Context context) {
String versionName = "";
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo = packageManager.getPackageInfo("cn.testgethandsetinfo", 0);
versionName = packageInfo.versionName;
if (TextUtils.isEmpty(versionName)) {
return "";
}
} catch (Exception e) {
e.printStackTrace();
}
return versionName;
}
}
main.xml如下:
復(fù)制代碼 代碼如下:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_centerInParent="true"
/>
</RelativeLayout>
您可能感興趣的文章:
- Android StatusBar 透明化方法(不同的版本適配)
- 獲取android4.0版本sdcard路徑示例
- 解析Android獲取系統(tǒng)cpu信息,內(nèi)存,版本,電量等信息的方法詳解
- android 版本檢測(cè) Android程序的版本檢測(cè)與更新實(shí)現(xiàn)介紹
- Android通過aapt命令獲取apk詳細(xì)信息(包括:文件包名,版本號(hào),SDK等信息)
- Android編程獲取包名,版本信息及VersionName名稱的方法
- Android最新版本開發(fā)環(huán)境搭建圖文教程
- Android獲取手機(jī)的版本號(hào)等信息的代碼
- Android獲取應(yīng)用版本號(hào)與版本名稱
- Android程序版本更新之通知欄更新下載安裝
- 詳解Android版本適配:9.0 Pie
相關(guān)文章
Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析
這篇文章主要為大家介紹了Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
關(guān)于如何使用Flutter開發(fā)執(zhí)行操作系統(tǒng)shell命令的工具詳解
本文主要介紹如何在Flutter應(yīng)用中開發(fā)一個(gè)Android終端命令行工具,包括終端命令行頁面的布局設(shè)計(jì)、與Shell通信的基本原理、輸入輸出處理的基本技巧等,以及如何在具體應(yīng)用中利用終端命令行工具來執(zhí)行系統(tǒng)命令和與用戶進(jìn)行交互2023-06-06
Android實(shí)現(xiàn)倒計(jì)時(shí)的方案梳理
這篇文章主要介紹了Android實(shí)現(xiàn)倒計(jì)時(shí)的方案梳理,下面文章圍繞主題展開Android倒計(jì)時(shí)方案,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
Flutter上線項(xiàng)目實(shí)戰(zhàn)記錄之路由篇
這篇文章主要給大家介紹了關(guān)于Flutter上線項(xiàng)目實(shí)戰(zhàn)記錄之路由篇的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
android實(shí)現(xiàn)圖片驗(yàn)證碼方法解析(自繪控件)
本文主要介紹了android自繪控件的應(yīng)用--實(shí)現(xiàn)圖片驗(yàn)證碼方法案例,具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01
RxJava實(shí)戰(zhàn)之訂閱流基本原理示例解析
這篇文章主要為大家介紹了RxJava實(shí)戰(zhàn)之訂閱流基本原理示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
詳細(xì)分析Android-Zygote的啟動(dòng)過程
在Android系統(tǒng)中,所有的應(yīng)用程序進(jìn)程以及系統(tǒng)服務(wù)進(jìn)程SystemServer都是由Zygote進(jìn)程孕育(fork)出來的,這也許就是為什么要把它稱為Zygote(受精卵)的原因吧。由于Zygote進(jìn)程在Android系統(tǒng)中有著如此重要的地位,本文將詳細(xì)分析它的啟動(dòng)過程2021-06-06
android自定義組件實(shí)現(xiàn)儀表計(jì)數(shù)盤
這篇文章主要為大家詳細(xì)介紹了android自定義組件實(shí)現(xiàn)儀表計(jì)數(shù)盤,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11

