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 getVersionName(Context c) {
    try {/*  w w  w  .  ja va  2 s .c  o m*/
        PackageInfo info = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        return info.versionName;
    } catch (NameNotFoundException e) {
    }
    return null;
}

From source file:Main.java

public static PackageInfo packageInfoFromContext(final Context context) {
    try {/*ww w.ja  va2 s  .c  o  m*/
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (final PackageManager.NameNotFoundException x) {
        throw new RuntimeException(x);
    }
}

From source file:Main.java

public static int getRevision(Context context) {
    try {//from  w ww  . jav  a2  s  . c om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return -1;
    }
}

From source file:Main.java

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

From source file:Main.java

private static PackageInfo getPackageInfo(Context context) {
    try {//from w  w  w. j av a2  s .co  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        throw new RuntimeException("Could not get package name: " + e);
    }
}

From source file:Main.java

public static boolean isAppFilesPath(Context context, String path) {
    return !TextUtils.isEmpty(path) && path.contains("/Android/data/" + context.getPackageName() + "/files");
}

From source file:Main.java

public static String getVersionName(Context context) {
    String verName = "";
    try {/*from   ww  w.j a v a2s  .  co  m*/
        String packgeName = context.getPackageName();
        verName = context.getPackageManager().getPackageInfo(packgeName, 0).versionName;
    } catch (NameNotFoundException e) {
    }
    return verName;
}

From source file:Main.java

public static int getPeripheralsLeftIconResourceId(Resources resources, String drawableName, Context context) {
    return resources.getIdentifier(photo + drawableName.toLowerCase(), "drawable", context.getPackageName());
}

From source file:Main.java

private static String getResourcesPath(Context context, String url) {

    String dir = String.format("/Android/data/%s/files/", context.getPackageName());
    File sd = Environment.getExternalStorageDirectory();
    File filePath = new File(sd.getPath() + dir + "savedResources");
    filePath.mkdirs();//  www  .j a v  a2s  .  c om

    return filePath + url.substring(url.lastIndexOf("/"));
}

From source file:Main.java

public static boolean isAppCachePath(Context context, String path) {
    return !TextUtils.isEmpty(path) && path.contains("/Android/data/" + context.getPackageName() + "/cache");
}