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:org.ttrssreader.utils.Utils.java

/**
 * Retrieves the packaged version-code of the application
 *
 * @param c - The Activity to retrieve the current version
 * @return the version-string/*from w  w w  .ja v a  2 s .  com*/
 */
public static int getAppVersionCode(Context c) {
    int result;
    try {
        PackageManager manager = c.getPackageManager();
        PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0);
        result = info.versionCode;
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Unable to get application version: " + e.getMessage());
        result = 0;
    }
    return result;
}

From source file:org.ttrssreader.utils.Utils.java

/**
 * Retrieves the packaged version-name of the application
 *
 * @param c - The Activity to retrieve the current version
 * @return the version-string/*from   w w w.ja va2 s  .c  om*/
 */
public static String getAppVersionName(Context c) {
    String result;
    try {
        PackageManager manager = c.getPackageManager();
        PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0);
        result = info.versionName;
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Unable to get application version: " + e.getMessage());
        result = "";
    }
    return result;
}

From source file:net.bible.service.common.CommonUtils.java

public static String getApplicationVersionName() {
    String versionName = null;/*from  w  w  w .j a va 2 s . co m*/
    try {
        PackageManager manager = BibleApplication.getApplication().getPackageManager();
        PackageInfo info = manager.getPackageInfo(BibleApplication.getApplication().getPackageName(), 0);
        versionName = info.versionName;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Error getting package name.", e);
        versionName = "Error";
    }
    return versionName;
}

From source file:net.bible.service.common.CommonUtils.java

public static int getApplicationVersionNumber() {
    int versionNumber;
    try {//  w w w.  j av a 2  s. c o  m
        PackageManager manager = BibleApplication.getApplication().getPackageManager();
        PackageInfo info = manager.getPackageInfo(BibleApplication.getApplication().getPackageName(), 0);
        versionNumber = info.versionCode;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Error getting package name.", e);
        versionNumber = -1;
    }
    return versionNumber;
}

From source file:com.yibu.kuaibu.app.glApplication.java

/**
 * ????//w ww .  j a  v  a  2s  .co  m
 */
public static String getAppVersionName(Context context) {
    String versionName = "";
    try {
        // ---get the package info---
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        versionName = pi.versionName;
        if (versionName == null || versionName.length() <= 0) {
            return "";
        }
    } catch (Exception e) {
        Log.e("VersionInfo", "Exception", e);
    }
    return versionName;
}

From source file:fr.shywim.antoinedaniel.utils.Utils.java

/**
 * @return Application's version code from the {@code PackageManager}.
 *//* w w w.j  ava  2s . c  o  m*/
public static int getAppVersion(Context context) {
    try {
        PackageManager manager = context.getPackageManager();
        PackageInfo packageInfo = null;
        if (manager != null)
            packageInfo = manager.getPackageInfo(context.getPackageName(), 0);
        int version = 0;
        if (packageInfo != null)
            version = packageInfo.versionCode;
        return version;
    } catch (PackageManager.NameNotFoundException e) {
        // should never happen
        throw new RuntimeException("Could not get package name: " + e);
    }
}

From source file:Main.java

static boolean isSystemApp(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    ComponentName cn = intent.getComponent();
    String packageName = null;//from   w w  w  .  j a  va 2s .  co m
    if (cn == null) {
        ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if ((info != null) && (info.activityInfo != null)) {
            packageName = info.activityInfo.packageName;
        }
    } else {
        packageName = cn.getPackageName();
    }
    if (packageName != null) {
        try {
            PackageInfo info = pm.getPackageInfo(packageName, 0);
            return (info != null) && (info.applicationInfo != null)
                    && ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
        } catch (NameNotFoundException e) {
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.bellman.bible.service.common.CommonUtils.java

public static String getApplicationVersionName() {
    String versionName = null;/*  ww  w. ja  va2s .  c  o m*/
    try {
        PackageManager manager = CurrentActivityHolder.getInstance().getApplication().getPackageManager();
        PackageInfo info = manager
                .getPackageInfo(CurrentActivityHolder.getInstance().getApplication().getPackageName(), 0);
        versionName = info.versionName;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Error getting package name.", e);
        versionName = "Error";
    }
    return versionName;
}

From source file:com.bellman.bible.service.common.CommonUtils.java

public static int getApplicationVersionNumber() {
    int versionNumber;
    try {//from   w  ww. j a  v  a2 s. co m
        PackageManager manager = CurrentActivityHolder.getInstance().getApplication().getPackageManager();
        PackageInfo info = manager
                .getPackageInfo(CurrentActivityHolder.getInstance().getApplication().getPackageName(), 0);
        versionNumber = info.versionCode;
    } catch (final NameNotFoundException e) {
        Log.e(TAG, "Error getting package name.", e);
        versionNumber = -1;
    }
    return versionNumber;
}

From source file:com.cliff.comichelper.MainActivity.java

public static String getAppVersionName(Context context) {
    String versionName = "";
    try {//from  www .j ava 2s  .  com
        // ---get the package info---  
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        versionName = pi.versionName;
        if (versionName == null || versionName.length() <= 0) {
            return "";
        }
    } catch (Exception e) {
        Log.e("VersionInfo", "Exception", e);
    }
    return versionName;
}