Tutorials Android How to Programmatically Get Application Version in Android?

How to Programmatically Get Application Version in Android?

Use the following code snippet to, get Android application version from code. The PackageInfo class provides overall information about the contents of a package. This corresponds to all of the information collected from AndroidManifest.xml.

public String getAppVersion() {
        PackageInfo pInfo;
        try {
            pInfo = MyApp.getInstance().getPackageManager().getPackageInfo(MyApp.getInstance().getPackageName(), 0);
            return new StringBuilder("v").append(pInfo.versionName)
                    .append(" (").append(pInfo.versionCode).append(")").toString();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "1.0.0";
    }
Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post
Embed Google Map into Your Website

How To Embed a Map into Your Website Using Google Maps

Next Post

How to Create a New Template in Google Docs

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x