Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

android - 如何获取您的Android应用程序的内部版本号?(How to get the build/version number of your Android application?)

I need to figure out how to get or make a build number for my Android application.

(我需要弄清楚如何获取或制作Android应用程序的内部版本号。)

I need the build number to display in the UI.

(我需要内部版本号才能显示在UI中。)

Do I have to do something with AndroidManifest.xml ?

(我必须对AndroidManifest.xml做些事情吗?)

  ask by Fahad Ali Shaikh translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use:

(使用:)

try {
    PackageInfo pInfo = context.getPackageManager().getPackageInfo(getPackageName(), 0);
    String version = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
}

And you can get the version code by using this

(您可以使用此代码获取版本代码)

int verCode = pInfo.versionCode;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...