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 PackageInfo getPackageInfo(Context context) throws PackageManager.NameNotFoundException {
    PackageManager manager = context.getPackageManager();
    return manager.getPackageInfo(context.getPackageName(), 0);
}

From source file:Main.java

private static boolean isAppInstalled(Context context, String uri) {
    try {//  ww  w.  ja  v  a 2 s. c  o  m
        PackageManager pm = context.getPackageManager();
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String getVersion(Context context) throws PackageManager.NameNotFoundException {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
    return info.versionName;
}

From source file:Main.java

public final static boolean isInstall(String pkg, Context ctx) {
    PackageManager pm = ctx.getPackageManager();
    try {//from   w  w w . ja  v  a  2 s  . c  o  m
        pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static PackageInfo getAppVersionInfo(Context context) {
    PackageInfo pi = null;//from   ww w  . j  av  a  2 s.c  o  m
    try {
        // ---get the package info---  
        PackageManager pm = context.getPackageManager();
        pi = pm.getPackageInfo(context.getPackageName(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return pi;
}

From source file:Main.java

public static PackageInfo loadPackageInfo(PackageManager mPm, String packageName) {
    try {/*from   w ww  .  j a  v a 2s  .  c o  m*/
        return mPm.getPackageInfo(packageName, PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
    } catch (NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static boolean isPackageInstalled(String packageName, PackageManager pm) {
    try {//from  ww w.j ava 2s.  c  om
        String mVersion = pm.getPackageInfo(packageName, 0).versionName;
        if (mVersion == null) {
            return false;
        }
    } catch (NameNotFoundException notFound) {
        Log.e(TAG, "Package could not be found!", notFound);
        return false;
    }
    return true;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static boolean TakeIsInstallApk(String abPath, Context context) {
    PackageManager pm = context.getPackageManager();
    try {// w w w.j av a2  s.co m
        pm.getPackageInfo(abPath, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}