List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
/** * Returns the version code of the currently running app * @param context//from www . jav a2 s . co m * @return */ public static int getInstallVersionCode(Context context) { int version = -1; try { version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return version; }
From source file:Main.java
public static int getVersionCode(Context context) { int versionCode; try {//from w ww . ja v a 2s . c o m versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { versionCode = INVALID_VERSION_CODE; } return versionCode; }
From source file:Main.java
public static int getDbVersion(Context context) { int versionCode = 1; try {//from ww w . j av a 2 s. c om versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { // pass } return versionCode; }
From source file:Main.java
public static Intent getMarketIntent(Context context) { StringBuilder localStringBuilder = new StringBuilder().append("market://details?id="); String str = context.getPackageName(); localStringBuilder.append(str);//from w w w. j a v a2 s .c om Uri localUri = Uri.parse(localStringBuilder.toString()); return new Intent(Intent.ACTION_VIEW, localUri); }
From source file:Main.java
public static String getMyAppVersion(Context context) { String version = ""; try {/*from w w w . j av a 2 s . com*/ PackageInfo i = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); version = i.versionName; } catch (PackageManager.NameNotFoundException e) { } return version; }
From source file:Main.java
public static File getProperApplicationExternalDirectory(Context c) { File ret = new File(Environment.getExternalStorageDirectory().toString() + "/Android/data/" + c.getPackageName() + "/files/"); ret.mkdirs();//from www . jav a2s.c o m return ret; }
From source file:Main.java
public static int getVerCode(Context paramContext) { PackageInfo pInfo;//from w ww .j a va2s . co m try { pInfo = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(), 0); return pInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static String getVersionName(Context context) { String versionName = null;//from w w w .j a va 2 s . c o m try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException ignored) { } return versionName; }
From source file:Main.java
/** * @return Application's version code from the {@code PackageManager}. *//* w ww .j a v a 2s . c om*/ public static int getAppVersion(Context mContext) { try { PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(mContext.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 String getVersionName(Context context) { String versionName = null;/* w w w . j a v a 2 s .c om*/ try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return versionName; }