does Package Exist - Android App

Android examples for App:Package

Description

does Package Exist

Demo Code

// Licensed under the Apache License, Version 2.0
//package com.java2s;
import android.content.Context;
import android.content.pm.PackageInfo;

import android.content.pm.PackageManager.NameNotFoundException;

public class Main {
    public static boolean doesPackageExist(Context context,
            String packageName) {
        try {//w w  w  .  ja va  2 s  .c  o  m
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    packageName, 0);
            if (null == info) {
                return false;
            }
            return true;
        } catch (NameNotFoundException e) {
            return false;
        }
    }
}

Related Tutorials