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 the target app is currently available on the device
     * @param context
     * @param targetPackageName
     * @return
     */
    public static boolean isTargetAppAvailable(Context context, String targetPackageName) {
        PackageManager pm = context.getPackageManager();
        try {
            pm.getApplicationInfo(targetPackageName, 0);
            return true;
        } catch (PackageManager.NameNotFoundException ne) {
            return false;
        }
    }
}