List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static List<ResolveInfo> getAvailableAppsForIntent(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); return packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); }
From source file:Main.java
public static int getVersionCode(Context context) { try {//from w ww .j av a 2s.c om PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static Intent getLaucher(String otherPackage, Context context) { PackageManager packageManager = (PackageManager) context.getPackageManager(); return packageManager.getLaunchIntentForPackage(otherPackage); }
From source file:Main.java
public static boolean isAppInstalled(Context context, String pkgName) { PackageManager pm = context.getPackageManager(); boolean installed = false; try {//from w ww.j ava2 s .c o m pm.getPackageInfo(pkgName, PackageManager.GET_ACTIVITIES); installed = true; } catch (PackageManager.NameNotFoundException e) { installed = false; } return installed; }
From source file:Main.java
public static boolean hasPreferredApplication(final Context context, final Intent intent) { PackageManager pm = context.getPackageManager(); ResolveInfo info = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); return !"android".equals(info.activityInfo.packageName); }
From source file:Main.java
public static String getVersionName(Context context) { try {//from w w w . ja v a 2 s . co m String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; return versionName; } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getAppLabel(Context context, ApplicationInfo info) { PackageManager pManager = context.getPackageManager(); return pManager.getApplicationLabel(info).toString(); }
From source file:Main.java
public static boolean isPackageExists(Context context, String targetPackage) { try {/*from ww w . j a va2s. co m*/ context.getPackageManager().getPackageInfo(targetPackage, PackageManager.GET_ACTIVITIES); } catch (Exception ex) { return false; } return true; }
From source file:Main.java
public static boolean checkPermission(Context context, String permissionName) { PackageManager pkm = context.getPackageManager(); boolean has_permission = (PackageManager.PERMISSION_GRANTED == pkm.checkPermission(permissionName, context.getPackageName()));/*from ww w.ja v a 2 s.c o m*/ return has_permission; }
From source file:Main.java
public static boolean checkPermission(Context context, String permission) throws NullPointerException { return context.getPackageManager().checkPermission(permission, context.getPackageName()) != 0; }