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 PackageInfo getPackageInfo(Context context, String archiveFilePath) {
    PackageManager pm = context.getPackageManager();
    return pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {/*  w w  w  .j  a v  a 2  s.  c  om*/
        PackageInfo manager = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return manager.versionName;
    } catch (Exception e) {
        return "Unknown";
    }
}

From source file:Main.java

public static int queryIntentActivitiesSize(Context ctx, Intent intent) {
    PackageManager packageManager = ctx.getPackageManager();
    List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size();
}

From source file:Main.java

/**
 * @param ctx The Android application context.
 * @return Application name/*  w ww.  java 2 s.  c  om*/
 */
public static String getAppName(Context ctx) {
    PackageManager packageManager = ctx.getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {
        applicationInfo = packageManager.getApplicationInfo(ctx.getApplicationInfo().packageName, 0);
    } catch (final NameNotFoundException ignored) {
    }
    return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
}

From source file:Main.java

public static boolean isApkInstalled(Context context) {
    PackageManager pm = context.getPackageManager();

    //      Intent intent = new Intent(Intent.ACTION_MAIN, null);
    //      intent.addCategory(Intent.CATEGORY_DEFAULT);
    //      intent.setPackage("com.cnnct.zfwgpy");
    Intent intent = new Intent();
    intent.setPackage("com.cnnct.zfwgpy");
    List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
    if (apps != null && apps.size() > 0) {
        return true;
    }//from w  ww.  j  a va 2s.c  o  m
    return false;
}

From source file:Main.java

public static String getPackageName(Context ctx) {
    try {//from   ww w .  j av  a2 s . c  om
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        return info.packageName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//from   ww w  . j a  va 2 s .com
        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pInfo.versionName;
    } catch (PackageManager.NameNotFoundException ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getAppVersionCode(Context context) {
    try {/*from w  w w.  j a v  a  2 s.  c  om*/
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return 1;
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//from   w  w w  . j av a 2s  .  c  om
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pi.versionName;

    } catch (NameNotFoundException e) {
        return "";
    }
}

From source file:Main.java

public static void startApplication(Context context, String packageName) {

    PackageManager pm = context.getPackageManager();
    Intent intent = pm.getLaunchIntentForPackage(packageName);
    context.startActivity(intent);/*  ww w .jav  a  2 s.  co  m*/

}