is App Installed - Android App

Android examples for App:App Install

Description

is App Installed

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;

public class Main {
    private static final int NO_FLAG = 0;

    public static boolean isAppInstalled(Context context, String packageName) {
        if (packageName == null || packageName.equals("")) {
            return false;
        }//from  w  w w  .j  a  v a  2 s . c o m
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(packageName, NO_FLAG);
            if (pi == null) {
                return false;
            }
        } catch (NameNotFoundException e) {
            return false;
        }

        return true;
    }
}

Related Tutorials