List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static String getVersionCode(Context context, int type) { try {/*from ww w .j a v a 2s . co m*/ PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (type == 1) { return String.valueOf(pi.versionCode); } else { return pi.versionName; } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
/** * Register a receiver both for internal broadcast or system broadcast. */// w ww .j a v a 2 s. c om public static Intent register(@NonNull Context cxt, @NonNull BroadcastReceiver receiver, @NonNull IntentFilter filter) { String perm = cxt.getPackageName() + PERM_COMMON_BROADCAST; return cxt.registerReceiver(receiver, filter, perm, null); }
From source file:Main.java
public static String getApplicationVersion(Context context) { PackageInfo pInfo;/*from w ww .j ava 2 s. co m*/ try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getVerName(Context context) { String verName = ""; try {//from w w w . j a v a2 s . c o m verName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return verName; }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context) { PackageInfo pkg = null;/*from w w w. jav a2 s . co m*/ try { pkg = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); } catch (NameNotFoundException exp) { exp.printStackTrace(); } return pkg; }
From source file:Main.java
public static String getVerionName(Context context) { try {/* w w w . j a v a 2s. c o m*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static int getVersionCode(Context context) { try {// ww w. ja v a 2s . com PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return -1; } catch (NullPointerException e) { e.printStackTrace(); return -1; } }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context) { PackageInfo info = null;/*from w w w. j a va 2s .c o m*/ try { String packageName = context.getPackageName(); info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); } catch (Exception e) { e.printStackTrace(); } return info; }
From source file:Main.java
public static String getVersion(Context context) { String version = ""; try {/*from w ww .ja va2 s. c o m*/ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { return "unkown"; } }
From source file:Main.java
/** * Returns the file name (without full path) for an Expansion APK file from the given context. * //from w ww. j av a2s. c o m * @param c the context * @param mainFile true for main file, false for patch file * @param versionCode the version of the file * @return String the file name of the expansion file */ public static String getExpansionAPKFileName(Context c, boolean mainFile, int versionCode) { return (mainFile ? "main." : "patch.") + versionCode + "." + c.getPackageName() + ".obb"; }