Android獲取手機(jī)型號(hào)/系統(tǒng)版本號(hào)/App版本號(hào)等信息實(shí)例講解
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>
- Android StatusBar 透明化方法(不同的版本適配)
- 獲取android4.0版本sdcard路徑示例
- 解析Android獲取系統(tǒng)cpu信息,內(nèi)存,版本,電量等信息的方法詳解
- android 版本檢測(cè) Android程序的版本檢測(cè)與更新實(shí)現(xiàn)介紹
- Android通過(guò)aapt命令獲取apk詳細(xì)信息(包括:文件包名,版本號(hào),SDK等信息)
- Android編程獲取包名,版本信息及VersionName名稱(chēng)的方法
- Android最新版本開(kāi)發(fā)環(huán)境搭建圖文教程
- Android獲取手機(jī)的版本號(hào)等信息的代碼
- Android獲取應(yīng)用版本號(hào)與版本名稱(chēng)
- Android程序版本更新之通知欄更新下載安裝
- 詳解Android版本適配:9.0 Pie
相關(guān)文章
Android RecyclerView上拉加載更多功能回彈實(shí)現(xiàn)代碼
這篇文章主要介紹了Android RecyclerView上拉加載更多功能回彈實(shí)現(xiàn)代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02Android上使用ZXing識(shí)別條形碼與二維碼的方法
這篇文章主要介紹了Android上使用ZXing識(shí)別條形碼與二維碼的方法,需要的朋友可以參考下2014-08-08Android 優(yōu)雅的實(shí)現(xiàn)通用格式化編輯
這篇文章主要介紹了Android 優(yōu)雅的實(shí)現(xiàn)通用格式化編輯,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03Android 7.0行為變更 FileUriExposedException解決方法
這篇文章主要介紹了Android 7.0行為變更 FileUriExposedException解決方法的相關(guān)資料,需要的朋友可以參考下2017-05-05Android 組件Gallery和GridView示例講解
本文主要講解Android 組件Gallery和GridView,這里詳細(xì)介紹組件Gallery和GridView的知識(shí)要點(diǎn),并附示例代碼和實(shí)現(xiàn)效果圖,有興趣的小伙伴可以參考下2016-08-08Android電話撥號(hào)器實(shí)現(xiàn)方法
這篇文章主要介紹了Android電話撥號(hào)器實(shí)現(xiàn)方法,可實(shí)現(xiàn)模擬Android電話撥號(hào)的功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-09-09Android編程中聊天頁(yè)面背景圖片、標(biāo)題欄由于鍵盤(pán)引起問(wèn)題的解決方法
這篇文章主要介紹了Android編程中聊天頁(yè)面背景圖片、標(biāo)題欄由于鍵盤(pán)引起問(wèn)題的解決方法,針對(duì)鍵盤(pán)彈出時(shí)標(biāo)題欄及背景圖片異常的相關(guān)解決方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Android APK文件在電腦(PC虛擬機(jī))上面運(yùn)行方法
APK是Android系統(tǒng)的發(fā)布的工程包,很多時(shí)候我們想在電腦上而非Android手機(jī)上面運(yùn)行它,需要的朋友可以了解下2012-12-12