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 boolean isGuided(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    return pref.getBoolean(IS_GUIDED, false);
}

From source file:Main.java

public static void rateApplication(Context context) {
    Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {//  w  w  w .  j ava 2s  .c  om
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        //            UtilityClass.showAlertDialog(context, ERROR, "Couldn't launch the market", null, 0);
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {/* www  . j a va2 s .co  m*/
        final String PackageName = context.getPackageName();
        return context.getPackageManager().getPackageInfo(PackageName, 0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static void setGuided(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    pref.edit().putBoolean(IS_GUIDED, true).commit();
}

From source file:Main.java

public static File getExternalPackageDir(Context context) {
    return new File(getExternalDataDir(), context.getPackageName());
}

From source file:Main.java

/**
 * Start intent using an activity inside this app. This method is useful if you are certain
 * that the intent can be handled inside this app, and you care about shaving milliseconds.
 *///  w w w  .  j  ava 2 s.  c o  m
public static void startActivityInApp(Context context, Intent intent) {
    String packageName = context.getPackageName();
    intent.setPackage(packageName);
    context.startActivity(intent);
}

From source file:Main.java

public static void logOut(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    pref.edit().putString(ACCESS_TOKEN, "").putString(EXPIRES_IN, "").putString(UID, "").commit();
}

From source file:Main.java

/**
 * Starts Google Play application for this application.
 * @param context/*from  w  w  w .  ja va  2  s.c o  m*/
 */
public static void startGooglePlay(Context context) {
    final String appPackageName = context.getPackageName();// context.getPackageName();
    // //
    // getPackageName()
    // from Context
    // or Activity
    // object
    try {
        context.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
    }
}

From source file:Main.java

public static String getStringResource(Context context, String name, String defaultValue) {
    String packageName = context.getPackageName();
    int resId = context.getResources().getIdentifier(name, "string", packageName);
    if (resId != 0)
        return context.getResources().getString(resId);
    else//from  w  w  w. ja  v a  2  s.  c o  m
        return defaultValue;
}

From source file:Main.java

static String getStringResourceByName(String name, Context context) {
    try {//  w w  w  .j  a v  a  2 s  . c  o m
        String packageName = context.getPackageName();
        int resId = context.getResources().getIdentifier(name, "string", packageName);
        return context.getString(resId);
    } catch (Exception ignored) {
    }
    return null;
}