List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static int getVersionCode(Context context) { try {/*from ww w. ja va 2s . co m*/ PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pInfo.versionCode; } catch (NameNotFoundException nnfe) { Log.e(TAG, "Error finding version code: " + nnfe); } return -1; }
From source file:Main.java
public static void goGoogleMarket(Context context) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("market://search?q=" + context.getPackageName())); context.startActivity(i);/*www. j a v a 2 s . c om*/ }
From source file:Main.java
public static void setPreferences(Context context, String key, String value) { SharedPreferences sharedPreferences = context.getSharedPreferences(context.getPackageName(), context.MODE_PRIVATE);/*from w w w . j a v a 2 s . c om*/ Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.commit(); }
From source file:Main.java
/** * Converte uma chave em um texto presente no STRING.XML. * // w w w . j a va2 s.com * @param context * Contexto onde se encontram o mapeamento de strings * @param chave * Chave do texto a ser convertido * @return */ public static String getString(Context context, String chave) { return context.getString(context.getResources().getIdentifier(chave, "string", context.getPackageName())); }
From source file:Main.java
/** * Check if the IME specified by the context is enabled. * CAVEAT: This may cause a round trip IPC. * * @param context package context of the IME to be checked. * @param imm the {@link InputMethodManager}. * @return true if this IME is enabled./*from www. j a va 2s . com*/ */ public static boolean isThisImeEnabled(final Context context, final InputMethodManager imm) { final String packageName = context.getPackageName(); for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) { if (packageName.equals(imi.getPackageName())) { return true; } } return false; }
From source file:Main.java
public static void putFloat(Context context, String key, float value) { if (sp == null) { sp = context.getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE); }//from w w w .j ava2s.co m SharedPreferences.Editor editor = sp.edit(); editor.putFloat(key, value); editor.commit(); }
From source file:Main.java
/** * Restart application (just relauch the first page of package) * * * @param context Context// ww w. j av a 2 s. c om */ public static void restartApplication(Context context) { final Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(intent); }
From source file:Main.java
public static String getPackageName(Context context) { try {/*from ww w. ja va 2 s.c om*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.packageName; } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getAppVersion(Context context) { try {/*from w w w. j a v a 2 s . co m*/ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return packageInfo.versionCode; } catch (NameNotFoundException e) { // should never happen throw new RuntimeException("Could not get package name: " + e); } }
From source file:Main.java
/** * a helper to get the string fields from the R class * * @param ctx/*from ww w .j a va 2 s.c om*/ * @return */ public static String[] getFields(Context ctx) { Class rStringClass = resolveRClass(ctx.getPackageName()); if (rStringClass != null) { return getDefinedFonts(ctx, rStringClass.getFields()); } return new String[0]; }