Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.content.pm.PackageManager;

public class Main {
    /**
     * Checks if app given by package name is installed on device.
     * 
     * @param packageName
     *            The package name where the app should be found
     * @return true if app is installed on device. false if not.
     */
    public static boolean isInstalled(String packageName, Context ctx) {
        PackageManager pm = ctx.getPackageManager();
        try {
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
}