Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.content.pm.PackageInfo;

import java.util.List;

public class Main {

    public static String getAppVersionNameString(Context ctx, String packageName) {
        List<PackageInfo> pkgs = ctx.getPackageManager().getInstalledPackages(0);
        for (PackageInfo pi : pkgs) {
            if (pi.packageName.equals(packageName)) {
                return pi.versionName;
            }
        }
        return null;
    }
}