Example usage for android.content Context getPackageName

List of usage examples for android.content Context getPackageName

Introduction

In this page you can find the example usage for android.content Context getPackageName.

Prototype

public abstract String getPackageName();

Source Link

Document

Return the name of this application's package.

Usage

From source file:Main.java

/**
 * Method to get the last assumed Stage of the active session 
 * /*from   w  w w  .  j a v  a  2s  . c o  m*/
 * @param context Context
 * @return Last assumed Stage of the active session 
 */
public static int getActiveSessionStage(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

    return prefs.getInt(PREFS_KEY_STAGE, 0);
}

From source file:Main.java

public static int getAppVersionCode(Context ctx) {
    int result = -1;

    try {/*from w  ww .ja v  a 2s .c o  m*/
        String pkg = ctx.getPackageName();
        result = ctx.getPackageManager().getPackageInfo(pkg, 0).versionCode;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

From source file:Main.java

/**
 *
 * @param ctx//from w  ww . j av a 2s .  com
 * @param key
 * @return
 */
public static boolean removeGlobalSetting(Context ctx, String key) {
    SharedPreferences setting = ctx.getSharedPreferences(ctx.getPackageName(), 0);
    return setting.edit().remove(key).commit();
}

From source file:Main.java

public static final int getVersion(Context ctx) {
    try {// w  ww.  ja  v  a 2 s .  c  o  m
        return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static void setStatusOfRenderResetSwitcher(Context context, boolean flag) {
    try {//from   w  w w.  j a  v a 2 s .  co  m
        context.getSharedPreferences(context.getPackageName(), 1).edit()
                .putBoolean("reset_default_render", flag).commit();
        return;
    } catch (Exception exception) {
        return;
    }
}

From source file:Main.java

public static int getDrawableID(Context context, String key) {
    return context.getResources().getIdentifier(key, "drawable", context.getPackageName());
}

From source file:Main.java

public static String getVersionName(Context context) {
    String versionName = null;/*w  w w .j  a v a2s  .c o  m*/
    String pkName = context.getPackageName();
    try {
        versionName = context.getPackageManager().getPackageInfo(pkName, 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionName;
}

From source file:Main.java

/**
 * Returns the Play Store product page URL for calling app
 *
 * @param context//from   ww  w.j av a 2 s.co  m
 */
public static String getPlayStoreProductPageURL(Context context) {
    return getPlayStoreProductPageURL(context.getPackageName());
}

From source file:Main.java

public static int getDimenId(Context context, String name) {
    return context.getResources().getIdentifier(name, "dimen", context.getPackageName());
}

From source file:Main.java

public static int getColorId(Context context, String name) {
    return context.getResources().getIdentifier(name, "color", context.getPackageName());
}