List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static int getStringResId(Context context, String name) { return context.getResources().getIdentifier(name, android.R.string.class.getSimpleName(), context.getPackageName()); }
From source file:Main.java
public static String getAppVersion(Context context) { PackageInfo pInfo = null;/* w ww.ja va 2 s .c o m*/ try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String version = pInfo.versionName; version.replaceAll(" ", ""); return version; }
From source file:Main.java
public static String getVersionName(Context context) { String versionName = ""; try {//from w w w . j a v a2 s . c o m versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static String getVersionName(Context app) { PackageInfo packageInfo = null;//from ww w .j a v a2s. c o m try { packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0); return packageInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static int getVersionCode(Context app) { PackageInfo packageInfo = null;/*from www . ja v a2s. c o m*/ try { packageInfo = app.getPackageManager().getPackageInfo(app.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static String getStringFromXml(Context context, String name) { if (context != null) { int id = context.getResources().getIdentifier(name, "string", context.getPackageName()); String text = context.getString(id); return text; } else {/*from ww w .ja v a 2 s .co m*/ return ""; } }
From source file:Main.java
public static int getResourceId(Context context, String resourceName, String resourceTypeName) { return context.getResources().getIdentifier(resourceName, resourceTypeName, context.getPackageName()); }
From source file:Main.java
public static int getAppVersionCode(Context context) { int versionCode = 0; try {//from w w w .j a va 2 s. c o m 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 String getCurrentVersionName(Context context) { String versionName = ""; try {/* w w w . ja v a 2s . co m*/ versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static int getResourceId(Context context, String key, String type) throws RuntimeException { int resource = context.getResources().getIdentifier(key, type, context.getPackageName()); if (resource == 0) { throw new RuntimeException("Missing resource " + key); }/*from w ww .ja v a 2 s . co m*/ return resource; }