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

/**
 * check if assign package is installed in system
 * *///from w ww .  ja va 2  s . c om
public static boolean isPackageInstalled(String packagename, Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

private static boolean appInstalledOrNot(String uri, Context context) {

    PackageManager pm = context.getPackageManager();
    boolean app_installed;
    try {//from w w  w .j av a  2 s.c  om
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}

From source file:Main.java

private static PackageInfo getApkInfo(Context context, String path) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);
    if (info != null) {
        return info;
    }/*from   ww w.j  av  a  2 s.  com*/
    return null;
}

From source file:Main.java

public static String getPackageNameByUid(Context context, int uid) {

    PackageManager pm = context.getPackageManager();
    String[] packageName = pm.getPackagesForUid(uid);
    if (packageName != null && packageName.length == 1) {
        return packageName[0];
    }/*from  w  ww  . ja v  a  2s .c  o m*/

    return "Null";
}

From source file:Main.java

public static boolean checkImplicitIntent(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
    return apps.size() > 0;
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    PackageManager manager = context.getPackageManager();
    PackageInfo info;//from w w w . j a va  2  s  .c  o  m
    String versionName = null;
    try {
        info = manager.getPackageInfo(context.getPackageName(), 0);
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e1) {
        e1.printStackTrace();
    }
    return versionName;
}

From source file:Main.java

public static boolean hasCamera(Context context) {
    if (context == null || context.getPackageManager() == null) {
        throw new IllegalArgumentException("Context and package manager must not be null");
    }// ww  w.  ja v a  2 s .  c  o m
    PackageManager pm = context.getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isMyServiceInstalled(Context ctx, Intent intent) {
    final PackageManager mgr = ctx.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

From source file:Main.java

public static boolean isApplicationInstalled(Context context, String packageName) {
    try {/* ww w .j  a  v a2  s .  com*/
        context.getPackageManager().getApplicationInfo(packageName, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static String getApkFilePackage(Context context, File apkFile) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkFile.getPath(), PackageManager.GET_ACTIVITIES);
    if (info != null) {
        return info.applicationInfo.packageName;
    }/*  w  w  w .  jav  a2s . co  m*/
    return null;
}