List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static int getStringId(Context context, String name) { return context.getResources().getIdentifier(name, "string", context.getPackageName()); }
From source file:Main.java
public static boolean wasInstalledFromGooglePlay(Context context) { String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName()); return "com.android.vending".equals(installer); }
From source file:Main.java
public static String getAppVersionName(Context ctx) { String result = "?"; try {/* w ww . java 2s . c o m*/ String pkg = ctx.getPackageName(); result = ctx.getPackageManager().getPackageInfo(pkg, 0).versionName; } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static void launchMarket(Context c) { Uri uri = Uri.parse("market://details?id=" + c.getPackageName()); // debug only Uri uri = //Uri.parse("https://market.android.com/details?id=" + getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); try {/*www.j a v a 2s . com*/ c.startActivity(goToMarket); } catch (ActivityNotFoundException e) { Toast.makeText(c, "XXX" /* R.string.couldnt_launch_market */, Toast.LENGTH_LONG).show(); } }
From source file:Main.java
public static int getId(Context context, String resName) { return context.getResources().getIdentifier(resName, "id", context.getPackageName()); }
From source file:Main.java
public static String getVersionName(Context ctx) { String packageName = ctx.getPackageName(); if (packageName.equals("com.MyGame.Midlet")) { return getVerNameFromAssert(ctx); } else {//from w w w . j a v a 2 s . co m return getAppVer(ctx, packageName); } }
From source file:Main.java
public static void dump(Context context) { Intent intent = new Intent(DUMP_ACTION); intent.setPackage(context.getPackageName()); context.sendBroadcast(intent);//w w w. j av a 2 s . com }
From source file:Main.java
/** * get application directory/*from ww w. j a v a 2 s . c om*/ * @param context * @return {@link String} * @throws Exception */ public static String getAppDataDir(Context context) throws Exception { return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.dataDir; }
From source file:Main.java
/** * /*from ww w. ja v a 2s . co m*/ * @return */ public static boolean isRunningForeground(Context mContext) { String packageName = mContext.getPackageName(); String topActivityClassName = getTopActivityName(mContext); System.out.println("packageName=" + packageName + ",topActivityClassName=" + topActivityClassName); if (packageName != null && topActivityClassName != null && topActivityClassName.startsWith(packageName)) { return true; } else { return false; } }
From source file:Main.java
public static Bitmap getAppIcon(Context context) { try {//from w w w . ja v a 2 s .c o m Class<?> drawableClass = Class.forName(context.getPackageName() + ".R$drawable"); Field f = drawableClass.getField("ic_launcher"); return BitmapFactory.decodeResource(context.getResources(), f.getInt(null)); } catch (Exception e) { return null; } }