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

public static int getVersionCode(Context context) {
    int verCode = 1;
    try {//from w w w  . ja v a 2 s . c o  m
        String packgeName = context.getPackageName();
        verCode = context.getPackageManager().getPackageInfo(packgeName, 0).versionCode;
    } catch (NameNotFoundException e) {
    }
    return verCode;
}

From source file:Main.java

public static int getResId(Context context, String id, String type) {
    return context.getResources().getIdentifier(id, type, context.getPackageName());
}

From source file:Main.java

public static int getCurrentVersionCode(Context context) {
    try {//  w w w .  ja va  2  s  .  c  om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {//from www .j ava 2s  .c  o  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return -1 + "";
    }
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {//from  w  w w.j  a va2s.  co  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:Main.java

public static int getStringId(Context context, String resName) {
    return context.getResources().getIdentifier(resName, "string", context.getPackageName());
}

From source file:Main.java

public static int getLayoutId(Context context, String resName) {
    return context.getResources().getIdentifier(resName, "layout", context.getPackageName());
}

From source file:Main.java

public static File getDataDir(Context context) {
    File file = new File(Environment.getExternalStorageDirectory(), context.getPackageName() + "/data");
    if (!file.exists()) {
        file.mkdirs();/*  ww  w  . j  a  v  a 2s.  c o m*/
    }

    return file;
}

From source file:Main.java

public static String getAppVersion(Context context) {
    try {/*w  ww .  ja  v a2 s  . co m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "Error";
    }
}

From source file:Main.java

/**
 * Method to set the new assumed Mode of the active session 
 * /*from  w w  w  .j ava  2  s . co  m*/
 * @param context
 * @param mode The new assumed Mode of the active session 
 */
public static void setActiveSessionMode(Context context, int mode) {
    SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

    prefs.edit().putInt(PREFS_KEY_MODE, mode).commit();
}