is Package Exists - Android App

Android examples for App:Package

Description

is Package Exists

Demo Code


//package com.java2s;

import android.content.Context;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class Main {

    public static boolean isPackageExists(Context context,
            String packageName) {
        if (null == packageName || "".equals(packageName)) {
            throw new IllegalArgumentException(
                    "Package name cannot be null or empty !");
        }/*  www  .  ja  v a2 s.co m*/
        try {
            ApplicationInfo info = context.getPackageManager()
                    .getApplicationInfo(packageName,
                            PackageManager.GET_UNINSTALLED_PACKAGES);
            return null != info;
        } catch (NameNotFoundException e) {
            return false;
        }
    }
}

Related Tutorials