is Installed by package name - Android App

Android examples for App:Package

Description

is Installed 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.text.TextUtils;

public class Main {

    public static boolean isInstalled(Context context, String packageName) {
        boolean installed = false;

        if (null == context || TextUtils.isEmpty(packageName)) {
            return false;
        }/*  w  ww  . j a v  a 2 s. c  om*/

        try {
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(packageName,
                            PackageManager.GET_UNINSTALLED_PACKAGES);
            if (null != packageInfo) {
                installed = true;
            }// end if
        } catch (NameNotFoundException e) {
            installed = false;
        }
        return installed;
    }
}

Related Tutorials