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

private static boolean isV4AInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    try {/* w  w  w  .  j ava  2 s. co  m*/
        pm.getPackageInfo("com.vipercn.viper4android_v2", PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    try {/*  w  w  w  .  j  av a  2s  .c o  m*/
        PackageInfo info = packageManager.getPackageInfo(context.getPackageName(), 0);
        return info.versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isInstalled(Context context, String packageName) {
    try {//from   ww w  .ja  v a2  s .  com
        context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String GetVersion(Context paramContext) {
    try {/*from www .  j  a  va2  s.  co m*/
        String str = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(),
                0).versionName;
        return str;
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
    }
    return "Unknown";
}

From source file:Main.java

public static String getPackageName(Context ctx) {
    try {/* w w  w .j  a  v a  2 s .  c  o  m*/
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        return info.packageName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String getVersion(Context context) {
    try {/*from ww w .j a  v  a  2s .  c  om*/
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pi.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static boolean isXposedInstalled(Context context) {
    PackageManager packageManager = context.getPackageManager();
    try {/*from  w  ww . jav a  2 s.c om*/
        packageManager.getPackageInfo(XPOSED_PACKAGE, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ECLAIR_MR1)
public static boolean canScan(Context context) {
    PackageManager pm = context.getPackageManager();
    return pm != null && pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:Main.java

public static void launchApp(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    Intent intent = pm.getLaunchIntentForPackage(packageName);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//from  w  ww  .  ja v a2s.  c  om
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    ApplicationInfo applicationInfo = null;
    try {/*from www  .  j  av a2 s .c  om*/
        applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0);
    } catch (final PackageManager.NameNotFoundException e) {
    }

    return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
}