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 void cleanDatabases(Context context) {
    deleteFilesByDirectory(new File("/data/data/" + context.getPackageName() + "/databases"));
}

From source file:Main.java

/**
 * Send a broadcast to internal receivers.
 *//*from  w w  w.j  ava 2s  .  com*/
public static void sendToInternal(@NonNull Context cxt, @NonNull Intent intent) {
    String perm = cxt.getPackageName() + PERM_COMMON_BROADCAST;
    intent.setPackage(cxt.getPackageName()); // only works on Android 4.0 and higher versions
    cxt.sendBroadcast(intent, perm);
}

From source file:Main.java

public static void cleanSharedPreference(Context context) {
    deleteFilesByDirectory(new File("/data/data/" + context.getPackageName() + "/shared_prefs"));
}

From source file:Main.java

public static String getDetails(Context context) {
    return "https://play.google.com/store/apps/details?id=" + context.getPackageName();
}

From source file:Main.java

public static final String getPlayStoreUrl(Context context) {
    return "https://play.google.com/store/apps/details?id=" + context.getPackageName();
}

From source file:Main.java

/**
 * helper class to retrieve a string by it's resource name
 *
 * @param ctx//from  www . j  av a2s. c om
 * @param resourceName
 * @return
 */
private static String getStringResourceByName(Context ctx, String resourceName) {
    String packageName = ctx.getPackageName();
    int resId = ctx.getResources().getIdentifier(resourceName, "string", packageName);
    if (resId == 0) {
        return "";
    } else {
        return ctx.getString(resId);
    }
}

From source file:Main.java

public static String getApplicationExternalStorageDirectory(Context context) {
    return String.format(APP_EXTERNAL_STORAGE_DIR_FORMAT, context.getPackageName());
}

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    pref.edit().clear().commit();/* w w  w .ja v a 2  s.  c om*/
}

From source file:Main.java

private static SharedPreferences getSharePreference(Context context) {
    return context.getSharedPreferences(context.getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS);
}

From source file:Main.java

public static boolean isMainProcess(Context context) {
    String packageName = context.getPackageName();
    String processName = getCurProcessName(context);
    return packageName.equalsIgnoreCase(processName);
}