List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
private static PackageInfo getPackageInfo(Context context, int flags) throws NameNotFoundException { return context.getPackageManager().getPackageInfo(context.getPackageName(), flags); }
From source file:Main.java
public static int getVersion(Context context) { try {/* www . j a v a 2s . c o m*/ PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionCode; } catch (PackageManager.NameNotFoundException ex) { ex.printStackTrace(); } return 0; }
From source file:Main.java
public static String getVersionName(Context context) { try {/* www . ja v a 2s. co m*/ PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionName; } catch (NameNotFoundException e) { return ""; } }
From source file:Main.java
/** * Restart the app./* w ww . j ava 2 s . co m*/ * @param context */ public static void restartApplication(Context context) { Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent p = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, p); //kill the application System.exit(0); }
From source file:Main.java
public static int getVersionNumber(Context context) { try {//from w w w.j av a 2 s. c o m PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 1; }
From source file:Main.java
public static int getStyleId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "style", paramContext.getPackageName()); }
From source file:Main.java
public static int getAppVersion(Context context) { try {//from w w w. j a va2 s .c o m PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return (pi.versionCode); } catch (NameNotFoundException e) { Log.i(TAG, "Package name not found"); } return (0); }
From source file:Main.java
public static int getStringArrayId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "array", paramContext.getPackageName()); }
From source file:Main.java
public static int getColorId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "color", paramContext.getPackageName()); }
From source file:Main.java
public static int getAppVersion(Context context) { try {//from www. j a v a 2 s. c om PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return info.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 1; }