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 getCurrentVersion(Context c) {
    String pkgName = c.getPackageName();
    try {//  w ww  .  j a va  2 s .  c  o m
        PackageInfo pinfo = c.getPackageManager().getPackageInfo(pkgName, PackageManager.GET_CONFIGURATIONS);
        return pinfo.versionName;
    } catch (Exception e) {
    }
    return "";
}

From source file:Main.java

public static int getAppVersionCode(Context context) {
    String pkName = context.getPackageName();
    try {//w ww  . ja  v a  2 s.c om
        return context.getPackageManager().getPackageInfo(pkName, 0).versionCode;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

public static String getAppName(Context context) {
    String pkName = context.getPackageName();
    try {/*from w w w .j  a v  a  2s .  c o  m*/
        return context.getPackageManager().getApplicationInfo(pkName, 0).loadLabel(context.getPackageManager())
                .toString();
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static String getDefaultPrefFilePath(Context context) {
    final String packageName = context.getPackageName();
    return "/data/data/" + packageName + "/shared_prefs/" + packageName + "_preferences.xml";
}

From source file:Main.java

public static String getDataPath(Context context) {

    return "/data/data/" + context.getPackageName();

}

From source file:Main.java

public static SharedPreferences getSharedPref(Context c) {
    return c.getSharedPreferences(c.getPackageName(), Context.MODE_PRIVATE);
}

From source file:Main.java

public static String getFrescoLocalResUrl(Context mContext, int resId) {
    return "res://" + mContext.getPackageName() + "/" + resId;
}

From source file:Main.java

/**
 * Get the App PackageName/*w ww  . j  a  v  a2  s.  co m*/
 * @param context
 * @return packeagename
 */
public static String getAppPackageName(Context context) {
    return context.getPackageName();
}

From source file:Main.java

public static boolean isSystem(Context context) {
    final String pname = context.getPackageName();
    int permissionForSystemStuff = context.getPackageManager()
            .checkPermission(android.Manifest.permission.MODIFY_PHONE_STATE, pname); // 0 means allowed
    if (permissionForSystemStuff == 0)
        return true;
    else/*from  w  w w.j a  v  a2s .  co m*/
        return false;
}

From source file:Main.java

public static String getAppName(Context context) {
    try {// w  ww  .ja v  a 2s.  c  o  m
        return context.getPackageName();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}