List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static boolean isPackageInstalled(Context context, String packagename) { PackageManager pm = context.getPackageManager(); try {/*from www .ja v a 2 s. c o m*/ PackageInfo info = pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); return info != null; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:Main.java
/** * @param context//from ww w.j av a2s. co m * the application context * @return true if the device has a rear camera, false else */ public static boolean hasCameraBack(Context context) { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA); }
From source file:Main.java
public static ApplicationInfo getApplicationInfo(Context context, String pkg) { try {/*w w w . j a v a2s . c om*/ return context.getPackageManager().getApplicationInfo(pkg, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String GetVersion(Context context) { try {//from www . j av a 2s . c om PackageInfo manager = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return manager.versionName; } catch (NameNotFoundException e) { return "Unknown"; } }
From source file:Main.java
/** * @param context//www.j a v a 2 s .c o m * @return Boolean * @throws * @Title: checkPhoneState * @Description: TODO */ private static Boolean checkPhoneState(Context context) { PackageManager pm = context.getPackageManager(); if (pm.checkPermission("android.permission.READ_PHONE_STATE", context.getPackageName()) != 0) { return false; } return true; }
From source file:Main.java
public static boolean canResolveBroadcast(Context context, Intent intent) { PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> receivers = packageManager.queryBroadcastReceivers(intent, 0); return receivers != null && receivers.size() > 0; }
From source file:Main.java
public static String getVersionName(Context context) { try {/*from w w w .j a v a2 s . c o m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static boolean isPackageInstalled(Context context, String pkgName) { PackageManager pm = context.getPackageManager(); try {/*from w w w . j a va 2s. c o m*/ PackageInfo pkgInfo = pm.getPackageInfo(pkgName, 0); return pkgInfo != null && pkgInfo.applicationInfo.enabled; } catch (PackageManager.NameNotFoundException e) { } return false; }
From source file:Main.java
public static Intent getDefaultClockIntent(Context context) { PackageManager pm = context.getPackageManager(); for (String packageName : CLOCK_PACKAGES) { try {// w ww . j a v a2 s . com pm.getPackageInfo(packageName, 0); return pm.getLaunchIntentForPackage(packageName); } catch (PackageManager.NameNotFoundException ignored) { } } return null; }
From source file:Main.java
public static boolean isPocketInstalled(Context context) { PackageManager pm = context.getPackageManager(); PackageInfo info;//ww w . j a v a 2 s . c om try { info = pm.getPackageInfo(PACKAGE, 0); } catch (PackageManager.NameNotFoundException e) { info = null; } return info != null; }