List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static void putString(Context context, String key, String value) { if (sp == null) { sp = context.getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE); }// w w w .j a va2 s.c o m SharedPreferences.Editor editor = sp.edit(); editor.putString(key, value); editor.commit(); }
From source file:Main.java
public static String getAppVersionName(Context context) { PackageInfo packageInfo = getPackageInfo(context.getPackageManager(), context.getPackageName()); return packageInfo != null ? packageInfo.versionName : ""; }
From source file:Main.java
static boolean hasPermission(Context context, String permission) { return (context.getPackageManager().checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED); }
From source file:Main.java
public static boolean needsMigration(Context context) { try {// ww w .j av a 2 s . c o m int currentVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); return !preferences.contains("migration_" + currentVersion); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static int getVersionCode(Context c) { PackageInfo pi = null;/*from w ww.jav a2 s . c o m*/ try { pi = c.getPackageManager().getPackageInfo(c.getPackageName(), PackageManager.GET_ACTIVITIES); } catch (NameNotFoundException e) { e.printStackTrace(); } return pi.versionCode; }
From source file:Main.java
public static int getDrawableId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "drawable", paramContext.getPackageName()); }
From source file:Main.java
private static boolean haveReadLogsPermission(Context context) { return context.getPackageManager().checkPermission("android.permission.READ_LOGS", context.getPackageName()) == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
public static int getDrawableId(@NonNull Context context, @NonNull String filename) { return context.getResources().getIdentifier(filename, "drawable", context.getPackageName()); }
From source file:Main.java
public static int getAppVersionCode(Context context) { try {/*ww w.j a va2s. co m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); if (packageInfo != null) { return packageInfo.versionCode; } } catch (Exception e) { } return 1; }
From source file:Main.java
public static String getVersion(Context context) { try {/*from ww w . ja va 2 s . c om*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionName; } catch (Exception e) { e.printStackTrace(); } return ""; }