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) {
    return getVersionCode(context, context.getPackageName());
}

From source file:Main.java

public static Integer getEmoticonResId(String emojiUnicode, Context c) {
    return c.getResources().getIdentifier("emoji_" + emojiUnicode, "drawable", c.getPackageName());
}

From source file:Main.java

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

From source file:Main.java

public static boolean isPasscodeSet(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

    if (prefs.getString(PREFS_KEY_PASSCODE, null) != null)
        return true;
    else/*  w w  w.ja  v  a  2  s  . c o  m*/
        return false;
}

From source file:Main.java

private static int getIconId(Context context, String targetPackage, String iconName) {
    if (targetPackage.equals(context.getPackageName())) {
        return context.getResources().getIdentifier(iconName, "drawable", targetPackage);
    }/*from w  ww  . j  a v a2s .c o  m*/
    return 0;
}

From source file:Main.java

private static String getSavedPostsPath(Context context) {
    String dir = String.format("/Android/data/%s/files/", context.getPackageName());
    File sd = Environment.getExternalStorageDirectory();
    String filePath = sd.getPath() + dir + "savedPosts.txt";

    new File(sd.getPath() + dir).mkdirs();

    return filePath;
}

From source file:Main.java

public static void restartApp(Context context) {
    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(i);//from   w  w w . ja  v  a  2s  .  c  om
}

From source file:Main.java

/**
 * Open the google play store market with this app
 * //from  w w w. j a  v  a 2  s .  c  o m
 * @param context the application context
 */
public static void openMarket(Context context) {
    Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);

    try {
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, "Couldn't launch the market", Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

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

From source file:Main.java

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