Android获取手机型号系统版本号App版本号等信息实例讲解

Android获取手机型号系统版本号App版本号等信息实例讲解,第1张

概述MainActivity如下:复制代码代码如下:packagecn.testgethandsetinfo;importandroid.os.Bundle;importandroid.text.TextUtils;importandroid.widget.TextView;importandroid.app.Activity;importandroid.content.Conte 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描述:
* 获得手机型号,系统版本,App版本号等信息
*/
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=
"手机型号:" + androID.os.Build.MODEL +
",SDK版本:" + androID.os.Build.VERSION.SDK +
",系统版本:" + androID.os.Build.VERSION.RELEASE+
",软件版本:"+getAppVersionname(MainActivity.this);
return handSetInfo;
}
//获取当前版本号
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获取手机型号/系统版本号/App版本号等信息实例讲解全部内容,希望文章能够帮你解决Android获取手机型号/系统版本号/App版本号等信息实例讲解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1141243.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存