List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static boolean isRunningForeground(Context context) { String packageName = context.getPackageName(); String topActivityClassName = getTopActivityName(context); if (packageName != null && topActivityClassName != null && topActivityClassName.startsWith(packageName)) { return true; } else {/*from w w w .j a v a2 s . c o m*/ return false; } }
From source file:Main.java
public static String getVersionCode(Context context) { String versionStr = ""; String pkName = context.getPackageName(); try {/*from ww w . jav a2 s . c om*/ versionStr = String.valueOf(context.getPackageManager().getPackageInfo(pkName, 0).versionCode); } catch (Exception e) { versionStr = "1"; e.printStackTrace(); } return versionStr; }
From source file:Main.java
public static int getID(Context context, String key) { return context.getResources().getIdentifier(key, "id", context.getPackageName()); }
From source file:Main.java
public static Spanned getStringResourceByName(Context context, String key) { String packageName = context.getPackageName(); int resId = context.getResources().getIdentifier(key, "string", packageName); if (resId == 0) { return Spannable.Factory.getInstance().newSpannable(key); } else {/*from ww w . j a v a 2 s. c o m*/ return Spannable.Factory.getInstance().newSpannable(context.getText(resId)); } }
From source file:Main.java
public static boolean isControllerEnabled(Context context) { SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE); // By default, when first time used, status is enabled return prefs.getBoolean(PREFS_CONTROLLER_STATUS, true); }
From source file:Main.java
public static int getVersionCode(Context context) { int versionCode = -1; String pkName = context.getPackageName(); try {/*from w ww . j a v a2s .c o m*/ versionCode = context.getPackageManager().getPackageInfo(pkName, 0).versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return versionCode; }
From source file:Main.java
/** get the current version of current application */ public static String getVersionName(Context context) { String versionName = ""; String pkName = context.getPackageName(); try {/*from w w w. j a v a 2 s . c om*/ versionName = context.getPackageManager().getPackageInfo(pkName, 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }
From source file:Main.java
public static File getAppCacheDir(Context context) { return new File(String.format(SDCARD_FOLDER_CACHE, context.getPackageName())); }
From source file:Main.java
public static String getFileRootPath(Context context) { return Environment.getExternalStorageDirectory() + "/Wstro/" + context.getPackageName(); }
From source file:Main.java
public static int getVersionCode(Context ctx) { try {/*ww w.j a v a 2 s. co m*/ return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode; } catch (Exception e) { return 0; } }