Example usage for android.content.pm PackageManager getPackageInfo

List of usage examples for android.content.pm PackageManager getPackageInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getPackageInfo.

Prototype

public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve overall information about an application package that is installed on the system.

Usage

From source file:Main.java

public static boolean isInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    try {//from w w w .  j  ava2  s . com
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

private static boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from  w ww. j  av  a  2s  .c o  m
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static int getApkVersion(Context context) throws PackageManager.NameNotFoundException {
    PackageManager pm = context.getPackageManager();
    PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
    return packageInfo.versionCode;
}

From source file:Main.java

public static int getVersionCode(Context context) throws NameNotFoundException {
    PackageManager manager = context.getPackageManager();
    PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
    int version = info.versionCode;
    return version;
}

From source file:Main.java

/**
 * Check if application with specific package name is installed on device*/
public static boolean isAppInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    try {/*from   w w w.j  a  v  a2  s  .  c o m*/
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

/**
 * Checks if app given by package name is installed on device.
 * //w w  w . ja  v  a 2s  .  c  o m
 * @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;
    }
}

From source file:Main.java

private static PackageInfo getPackageInfo(Context context) {
    PackageInfo pi = null;/*w  w w .j a  va  2  s  .  co m*/

    try {
        PackageManager pm = context.getPackageManager();
        pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS);

        return pi;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return pi;
}

From source file:Main.java

public static boolean isAppInstaled(Context context, String uri) {
    PackageManager pm = context.getPackageManager();
    try {// w w  w. jav  a  2  s  . c o  m
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);

        return true;
    } catch (PackageManager.NameNotFoundException e) {

        return false;
    }
}

From source file:Main.java

/**
 * Get application version.//from   w  w w .j a  va2 s  . co  m
 *
 * @param activity
 *          current activity.
 * @return application version. This equals to the version that appears in
 *         settings->application.
 * @throws android.content.pm.PackageManager.NameNotFoundException
 */
public static String getAppVersion(Activity activity) throws PackageManager.NameNotFoundException {
    PackageManager pm = activity.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(activity.getPackageName(), 0);
    return pi.versionName;
}

From source file:Main.java

public static boolean isPackageInstalled(Context context, String packageName) {
    final PackageManager pm = context.getPackageManager();
    try {/*  w  ww. j a va 2  s  .  co m*/
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}