List of usage examples for android.content Context getPackageManager
public abstract PackageManager getPackageManager();
From source file:Main.java
public static String getAppVersion(Context context) { PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo;/* w w w . ja va 2 s.c o m*/ try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getVersionNumber(Context context) { try {//from w w w . j a va2s . com PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static boolean isCameraFrontEnable(Context context) { PackageManager pm = (PackageManager) context.getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); for (FeatureInfo f : features) { if (PackageManager.FEATURE_CAMERA_FRONT.equals(f.name)) { return true; }/*from w w w . j a v a 2s . com*/ } return false; }
From source file:Main.java
public static int getAppVersion(Context context) { try {//from w ww.j av a 2 s.c o m PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return (pi.versionCode); } catch (NameNotFoundException e) { Log.i(TAG, "Package name not found"); } return (0); }
From source file:Main.java
public static void startActivity(Context context, String packageName) { Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName); if (intent != null) { context.startActivity(intent);/* w w w .j a v a2s. c o m*/ } }
From source file:Main.java
public static ApplicationInfo getApplicationInfo(Context context, String pkg) { try {// w w w .j a v a 2 s. c o m return context.getPackageManager().getApplicationInfo(pkg, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void turnOnFlash(Context context, Camera camera, int currentCameraId) { if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) { Parameters params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(params);/* w ww. j av a 2s . com*/ } }
From source file:Main.java
public static boolean isCameraFlashEnable(Context context) { PackageManager pm = (PackageManager) context.getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); for (FeatureInfo f : features) { if (PackageManager.FEATURE_CAMERA_FLASH.equals(f.name)) { return true; }//from w w w . j ava 2 s . c om } return false; }
From source file:Main.java
public static boolean isIntentAvailable(Context context, Intent intent) { List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0); return activities != null && activities.size() == 1; }
From source file:Main.java
public static PackageInfo getApkInfo(Context context, String archiveFilePath) { PackageManager pm = context.getPackageManager(); PackageInfo apkInfo = pm.getPackageArchiveInfo(archiveFilePath, 128); return apkInfo; }