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 String getDefaultRenderUDN(Context context) {
    String s;//from  w  w w. j av a  2 s  .  c o m
    try {
        s = context.getSharedPreferences(context.getPackageName(), 1).getString("default_render_udn", null);
    } catch (Exception exception) {
        exception.printStackTrace();
        return null;
    }
    return s;
}

From source file:Main.java

public static PackageInfo getPackage(Context context) {
    try {//ww  w.  j av  a2 s. c  o  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        // Should not happen
        return null;
    }
}

From source file:Main.java

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

From source file:Main.java

static public int getDrawable(Context ctx, String name) {
    return ctx.getResources().getIdentifier(name, "drawable", ctx.getPackageName());
}

From source file:Main.java

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

From source file:Main.java

public static Object getStyleableId(Context context, String resName) {
    return context.getResources().getIdentifier(resName, "styleable", context.getPackageName());
}

From source file:Main.java

public static int getVerCode(Context context) {
    int verCode = -1;
    try {//from  www .j ava2s. co  m
        String packageName = context.getPackageName();
        verCode = context.getPackageManager().getPackageInfo(packageName, 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return verCode;
}

From source file:Main.java

public static String get(Context context, String fieldName) {
    return get(context.getPackageName(), fieldName);
}

From source file:Main.java

public static PackageInfo getCurrentPackageInfo(Context context) {
    try {//from w w w .jav a2s  .  c  o m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getVerCode(Context context) {
    int verCode = -1;
    try {/*ww w  .  j ava 2 s.  com*/
        String packageName = context.getPackageName();
        verCode = context.getPackageManager().getPackageInfo(packageName, 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return verCode;
}