List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
/** * Get the application version (Version Code) * @param context/* ww w . ja va 2 s .co m*/ * @return */ public static int getApplicationVersion(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
public static int getStringId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "string", paramContext.getPackageName()); }
From source file:Main.java
/** * @return Application's version code from the {@code PackageManager}. *///from w ww . j a va 2s . c o m public static int getAppVersion(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { // should never happen throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
public static int getVersionCode(Context context) { try {/* ww w . java 2 s . com*/ final PackageInfo packInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static int getVersionCode(Context appContext) { try {// w w w .j a v a 2 s . c om PackageInfo packInfo = appContext.getPackageManager().getPackageInfo(appContext.getPackageName(), 0); return packInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return 1; } }
From source file:Main.java
/** * Gets application's package name.//from w w w. j a v a 2 s . com * @since 0.1.0 * @param aContext The context from which the package name is retrieved. * @return The package name. */ public static String getPackageName(Context aContext) { if (mPackageName == null) { mPackageName = aContext.getPackageName(); } return mPackageName; }
From source file:Main.java
public static String getStringByName(Context context, String name) { int resid = context.getResources().getIdentifier(name, "string", context.getPackageName()); if (resid == 0) return null; return context.getString(resid); }
From source file:Main.java
/** * @return Application's version code from the {@code PackageManager}. *//* w w w . j a v a 2s . co m*/ private static int getAppVersion(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { // should never happen throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
public static String getOldVersionPath(Context context) { try {//w w w. j ava2s .c o m ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); return appInfo.sourceDir; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static boolean isFirstPublish(Context context) { try {// w w w. j a v a2 s . c o m ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; return bundle.getBoolean("FIRST_LAUNCHER"); } catch (PackageManager.NameNotFoundException e) { return false; } }