List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static String getVersion(Context context) { String version = ""; try {/* w w w .j a v a 2s . co m*/ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); version = pi.versionName; } catch (PackageManager.NameNotFoundException e) { } return version; }
From source file:Main.java
public static String getVerName(Context context) { if (null == verName) { try {// w ww . j a v a2 s .c o m verName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (Exception e) { } } return verName; }
From source file:Main.java
public static int getCurrentVersion(Context context) { int versionCode = 0; try {//w w w. ja v a 2 s.c om PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionCode = info.versionCode; } catch (Exception e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static int getResourceId(Context context, String variableName) { try {/* www . j a v a 2s .co m*/ return context.getResources().getIdentifier(variableName, "drawable", context.getPackageName()); } catch (Exception e) { e.printStackTrace(); return -1; } }
From source file:Main.java
public static Bitmap getBitmapFromName(Context context, String resName) { opt.inPurgeable = true;//from w w w . ja va 2 s .com int resID = context.getResources().getIdentifier(resName, "drawable", context.getPackageName()); return BitmapFactory.decodeResource(context.getResources(), resID, opt); }
From source file:Main.java
public static int getVersionCode(Context context) { int versionCode = 0; try {/*from w ww .j a v a2s . c o m*/ PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionCode = i.versionCode; } catch (Exception e) { // do something } return versionCode; }
From source file:Main.java
public final static int getVersionCode(Context context) { int versionCode = 0; try {/*from w w w . j a va2 s . c o m*/ PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionCode = i.versionCode; } catch (Exception e) { // do something } return versionCode; }
From source file:Main.java
private static boolean compare(PackageInfo apkInfo, Context context) { if (apkInfo == null) { return false; }/*from w ww. j a va 2 s . c o m*/ String localPackage = context.getPackageName(); if (apkInfo.packageName.equals(localPackage)) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(localPackage, 0); Log.d("aa", "apkInfo.versionCode: " + apkInfo.versionCode + "-----packageInfo.versionCode:" + packageInfo.versionCode); if (apkInfo.versionCode > packageInfo.versionCode) { return true; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } return false; }
From source file:Main.java
public static int getAppVersionCode(Context context) { int versionCode = -1; try {/*from w w w .j a v a2 s . c o m*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionCode = info.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static File getTempFile(Context context) { //it will return /sdcard/image.tmp final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName()); if (!path.exists()) { path.mkdir();/*from w w w . j ava 2s. c om*/ } return new File(path, "image.jpg"); }