Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

import android.content.pm.PackageManager;

public class Main {
    /**
     * Checks if an App is Installed.
     *
     * @return true if installed false otherwise
     */
    public static boolean isAppInstalled(Context context, String packageName) {

        if (context == null)
            return false;

        PackageManager pm = context.getApplicationContext().getPackageManager();
        boolean isAppInstalled = false;
        try {

            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            isAppInstalled = true;

        } catch (PackageManager.NameNotFoundException e) {
            isAppInstalled = false;
        }

        return isAppInstalled;
    }
}