Example usage for android.content Context getPackageManager

List of usage examples for android.content Context getPackageManager

Introduction

In this page you can find the example usage for android.content Context getPackageManager.

Prototype

public abstract PackageManager getPackageManager();

Source Link

Document

Return PackageManager instance to find global package information.

Usage

From source file:Main.java

public static String getVersionName(Context con) {
    PackageManager pm = con.getPackageManager();
    PackageInfo pi = null;//  www. j  ava2  s .  c om
    try {
        pi = pm.getPackageInfo(con.getPackageName(), 0);
        return pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static String getVersion(Context act) {
    PackageManager pm = act.getPackageManager();
    try {//from  w w  w . j a v  a2 s  .co m
        PackageInfo packInfo = pm.getPackageInfo(act.getPackageName(), 0);
        return packInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        // can't reach
        return "";
    }
}

From source file:Main.java

public static Resources getRemoteResource(Context context) {
    try {/*from ww  w . ja va 2  s.co m*/
        return context.getPackageManager().getResourcesForApplication("com.google.android.gms");
    } catch (NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static String getAppVersion(Context context) {
    PackageManager pm = context.getPackageManager();
    try {/*from w w w . ja v a  2  s.co m*/
        PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
        return info.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static int getCurrentVersionCode(Context context) {
    try {/*w w  w .  ja  v a  2 s  .c o  m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//  w  w w .j  a  v a 2 s  .  c o m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return -1 + "";
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {/* www  .  ja v a2 s.  c o m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:Main.java

public static String getAppVersion(Context context) {
    try {//from w ww  .jav  a  2s  .  c  om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "Error";
    }
}

From source file:Main.java

@Nullable
public static Intent getLaunchIntent(Context context, String packageName) {
    return context.getPackageManager().getLaunchIntentForPackage(packageName);
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//from   w  w  w  . j  av  a 2s.co m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "Unknown";
}