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 getResClo(Context paramContext, String paramString) {
    return paramContext.getResources().getIdentifier(paramString, "color", paramContext.getPackageName());
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {/*w w  w. ja  va  2  s.  co  m*/
        PackageInfo pkg = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pkg.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static String getAppVersion(Context context) {
    try {/*from w  ww .j  a  v  a 2 s .  c  o m*/
        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        String version = pInfo.versionName;
        return version;
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    try {//  w w  w.j av  a  2  s.com
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return "unkonwn";
}

From source file:Main.java

public static void clearMyDefaultBrowser(Context context) {
    PackageManager pm = context.getPackageManager();
    pm.clearPackagePreferredActivities(context.getPackageName());
}

From source file:Main.java

public static void cleanDatabases(Context context) {
    deleteFilesByDirectory(new File(
            context.getFilesDir().getPath() + context.getPackageName() + File.separator + "databases"));
}

From source file:Main.java

public static void cleanSharedPreference(Context context) {
    deleteFilesByDirectory(new File(
            context.getFilesDir().getPath() + context.getPackageName() + File.separator + "shared_prefs"));
}

From source file:Main.java

public static String getVersion(Context context) {
    try {/*w ww. ja v  a2s . com*/
        PackageInfo manager = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return manager.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        return "--";
    }
}

From source file:Main.java

public static String GetVersion(Context paramContext) {
    try {//w  w  w .  j a v a  2s.  c  o m
        String str = paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(),
                0).versionName;
        return str;
    } catch (PackageManager.NameNotFoundException localNameNotFoundException) {
    }
    return "Unknown";
}

From source file:Main.java

public static String getSDKVersion(Context context) {
    PackageManager pm = context.getPackageManager();
    String pkgName = context.getPackageName();
    PackageInfo pkgInfo = null;/*  w ww. j  av  a  2 s. c  om*/
    String ret = "";
    try {
        pkgInfo = pm.getPackageInfo(pkgName, PackageManager.GET_CONFIGURATIONS);
        ret = pkgInfo.versionName;
    } catch (NameNotFoundException ex) {

    }
    return ret;
}