List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static int getAppVersion(Context context) { try {// ww w . ja v a 2 s. c o m PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { throw new RuntimeException("Coult not get package name: " + e); } }
From source file:Main.java
public static final String getApplicationVersionName(Context context) { try {/*from w ww. j a v a2 s .com*/ final PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap getDrawableBitmap(Context context, String rawName) { int id = context.getResources().getIdentifier(rawName, "drawable", context.getPackageName()); if (id != 0) { BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(id); if (drawable != null) { return drawable.getBitmap(); }// w w w . ja v a 2s .c om } return null; }
From source file:Main.java
public static String getPreferences(Context context, String key) { String data = ""; SharedPreferences pref = context.getSharedPreferences(context.getPackageName(), context.MODE_PRIVATE); data = pref.getString(key, ""); return data;/*from www. j a v a 2 s. c o m*/ }
From source file:Main.java
public static String getAppVersionName(Context context) { try {//from ww w . j a v a 2 s . co m PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getVersionName(Context context) { try {//from w ww . ja v a 2s.c om PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (info != null) { return info.versionName; } } catch (Exception e) { } return ""; }
From source file:Main.java
public static String getVersionName(Context context) { try {/* ww w. j a v a 2 s . c o m*/ PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionName; } catch (NameNotFoundException nnfe) { Log.e(TAG, "Error finding version code: " + nnfe); } return ""; }
From source file:Main.java
private static int getAppVersion(Context context) { try {//w w w.jav a2 s. co m PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static boolean isValidMessageApp(Context context) { return Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || context.getPackageName().equals(Sms.getDefaultSmsPackage(context)); }
From source file:Main.java
public static int getVersionCode(Context context) { try {/* w w w.j ava2s . c o m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (Exception e) { e.printStackTrace(); return 0; } }