List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
/** * Returns version number./*from w w w.j av a 2s . com*/ * * @param context Context * @return Version code */ public static int getVersionCode(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { return 0; } }
From source file:Main.java
public static boolean isIntentResolvable(Context context, Intent intent) { final PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, 0); return resolveInfo != null && !resolveInfo.isEmpty(); }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context, String pkg) { try {//from w w w . ja v a2 s .co m return context.getPackageManager().getPackageInfo(pkg, 0); } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getVersionCode(Context context) throws NameNotFoundException { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); int version = info.versionCode; return version; }
From source file:Main.java
/** * Returns version name.// w ww . j a va2 s . c o m * * @param context Context * @return Version name */ public static String getVersionName(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (NameNotFoundException e) { return ""; } }
From source file:Main.java
public static boolean isIntentAvailable(Context context, Intent intent) { final PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES); return list.size() > 0; }
From source file:Main.java
public static int getVersionCode(Context context) { try {/*from w w w . j a v a 2 s.co m*/ PackageManager packageManager = context.getPackageManager(); return packageManager.getPackageInfo(context.getPackageName(), 0).versionCode; } catch (Throwable error) { error.printStackTrace(); return 0; } }
From source file:Main.java
public static boolean isPkgInstalled(Context ctx, String packageName) { PackageManager pm = ctx.getPackageManager(); try {/*from w ww .j a va2 s . c o m*/ pm.getPackageInfo(packageName, 0); } catch (PackageManager.NameNotFoundException e) { return false; } return true; }
From source file:Main.java
public static void openApp(Context pContext, String pPackageName) { Intent launchIntent = pContext.getPackageManager().getLaunchIntentForPackage(pPackageName); pContext.startActivity(launchIntent); }
From source file:Main.java
/** * get all <uses-permission> tags included under <manifest> * //from w ww. ja v a2s . co m * @param context */ public static void getAllAppPermissions(Context context) { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo; try { // Array of all <uses-permission> tags included under <manifest>, or // null if there were none. packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS); String permissions[] = packageInfo.requestedPermissions; if (permissions != null) { // to list permission for (String permission : permissions) { Log.i("4A", "permission:" + permission); } } } catch (NameNotFoundException e) { e.printStackTrace(); } }