get Installed Apk Package Info - Android App

Android examples for App:APK Install and Uninstall

Description

get Installed Apk Package Info

Demo Code


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

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

import java.util.Iterator;
import java.util.List;

public class Main {

    public static PackageInfo getInstalledApkPackageInfo(Context context,
            String packageName) {
        PackageManager pm = context.getPackageManager();
        List<PackageInfo> apps = pm
                .getInstalledPackages(PackageManager.GET_SIGNATURES);

        Iterator<PackageInfo> it = apps.iterator();
        while (it.hasNext()) {
            PackageInfo packageinfo = it.next();
            String thisName = packageinfo.packageName;
            if (thisName.equals(packageName)) {
                return packageinfo;
            }//from www . j a  v a2  s.com
        }

        return null;
    }
}

Related Tutorials