List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getVersionName(Context context) { try {//from w w w. j av a 2 s . c o m PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionName; } catch (NameNotFoundException nnfe) { Log.e(TAG, "Error finding version code: " + nnfe); } return ""; }
From source file:Main.java
public static String getAppNameFromPkg(Context context, String pkg) { final PackageManager pm = context.getPackageManager(); ApplicationInfo ai;//from ww w .j av a 2 s . co m try { ai = pm.getApplicationInfo(pkg, 0); } catch (final PackageManager.NameNotFoundException e) { ai = null; } String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : pkg); return applicationName; }
From source file:Main.java
public static boolean isBLESupportedOnDevice(Context context) { return Build.VERSION.SDK_INT >= 19 && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE); }
From source file:Main.java
public static boolean isAppInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); boolean app_installed; try {//from w w w.j av a 2 s .c om pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; }
From source file:Main.java
private static boolean isIntentAvailable(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:Main.java
private static int getAppVersion(Context context) { try {/*w w w.j a v a 2 s.c om*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
public static Drawable getAppIconByPkgName(Context context, String packageName) { PackageManager pm = context.getPackageManager(); Drawable drawable = null;/* ww w . ja v a2 s .c o m*/ try { drawable = pm.getApplicationIcon(packageName); } catch (PackageManager.NameNotFoundException mE) { mE.printStackTrace(); } return drawable; }
From source file:Main.java
public static String getAppVersionString(Context ctx, String packageName) { List<PackageInfo> pkgs = ctx.getPackageManager().getInstalledPackages(0); for (PackageInfo pi : pkgs) { if (pi.packageName.equals(packageName)) { return pi.versionName; }/*w ww . j av a 2 s .c om*/ } return null; }
From source file:Main.java
public static boolean isIntentSafe(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return activities.size() > 0; }
From source file:Main.java
public static boolean isAppInstalled(Context context, String packageName) { PackageManager pm = context.getPackageManager(); boolean installed; try {//from w w w.j a v a 2 s .c o m pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); installed = true; } catch (PackageManager.NameNotFoundException e) { installed = false; } return installed; }