Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Mozilla Public License 

import android.app.Activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class Main {
    /**
     * Get application version.
     *
     * @param activity
     *          current activity.
     * @return application version. This equals to the version that appears in
     *         settings->application.
     * @throws android.content.pm.PackageManager.NameNotFoundException
     */
    public static String getAppVersion(Activity activity) throws PackageManager.NameNotFoundException {
        PackageManager pm = activity.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(activity.getPackageName(), 0);
        return pi.versionName;
    }
}