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 android.content.pm.PackageManager;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static boolean cheakByPackageName(Context context, String packageName, String sdkVersion) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        List<String> pName = new ArrayList<String>();
        List<String> versions = new ArrayList<String>();

        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                String appVersion = pinfo.get(i).versionName;
                pName.add(pn);
                versions.add(appVersion);
            }
        }

        if (!pName.contains(packageName)) {
            return false;
        } else {
            if (!versions.contains(sdkVersion)) {
                return false;
            }

        }
        return true;
    }
}