List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static String getStringByName(Context context, String name) { int id = context.getResources().getIdentifier(name, STRING, context.getPackageName()); return context.getString(id); }
From source file:Main.java
public static int getVersionCode(Context context) { int versionCode = 0; try {// w w w. j a v a2s. c o m String pkName = context.getPackageName(); versionCode = context.getPackageManager().getPackageInfo(pkName, 0).versionCode; } catch (Exception e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
public static int setBgImage(Context context, String color) { return context.getResources().getIdentifier(color, "drawable", context.getPackageName()); }
From source file:Main.java
public static PackageInfo getPackageInfo(Context context) { try {/*from w w w.j a v a2 s . c o m*/ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0); } catch (NameNotFoundException e) { return null; } }
From source file:Main.java
public static int getSharedTokenId(Context context) { int i;//from w ww. ja va 2 s .com try { i = context.getSharedPreferences(context.getPackageName(), 1).getInt("session_token_id", 0); } catch (Exception exception) { return 0; } return i; }
From source file:Main.java
/** * Returns the version name of the calling app * * @param context//ww w . ja v a 2 s .c o m * @return The version name of the app or <b>null</b> if it fails */ public static String getVersionName(Context context) { return getVersionName(context, context.getPackageName()); }
From source file:Main.java
/** * Returns the version code of the calling app * * @param context/*from www.j a va 2 s . c o m*/ * @return The version code of the app or 0 if it fails */ public static int getVersionCode(Context context) { return getVersionCode(context, context.getPackageName()); }
From source file:Main.java
public static String getLocalVersionName(Context context) { try {//w w w .ja v a 2 s . co m return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getAppVersionName(Context context) throws PackageManager.NameNotFoundException { String currentPackageName = context.getPackageName(); PackageInfo packageInfo = context.getPackageManager().getPackageInfo(currentPackageName, 0); return packageInfo.versionName; }
From source file:Main.java
/** * Check if your app is the default system SMS app. * @param context The Context/* w w w .j av a 2 s . c om*/ * @return True if it is default, False otherwise. Pre-KitKat will always return True. */ public static boolean isDefaultSmsApp(Context context) { if (hasKitKat()) { return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context)); } return true; }