has Installed Apk by package name - Android App

Android examples for App:APK Install and Uninstall

Description

has Installed Apk by package name

Demo Code


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

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;

public class Main {

    public static boolean hasInstallApk(Context context, String PackageName)
            throws NotFoundException {
        boolean flag = true;
        PackageManager mPm = context.getPackageManager();
        PackageInfo pkgInfo = null;//from www . jav  a 2  s.  com
        try {
            pkgInfo = mPm.getPackageInfo(PackageName,
                    PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
            flag = false;
        } catch (Exception ex) {
            flag = false;
            if (pkgInfo == null) {
                throw new NotFoundException();
            }
        }
        return flag;
    }
}

Related Tutorials