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 getVersionCode(Context context) {
    int versionCode = -1;
    try {//from   ww  w.j ava2 s. com
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        versionCode = info.versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionCode;
}

From source file:Main.java

public static int getDrawableResourceId(Context context, String name) {
    name = name.toLowerCase().replace(' ', '_');
    return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
}

From source file:Main.java

public static int getVersionCode(Context pContext) throws PackageManager.NameNotFoundException {
    PackageInfo pInfo = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), 0);
    return pInfo.versionCode;
}

From source file:Main.java

public static String getVersionName(Context context) {

    String versionCode = null;//from  www  .j  a  v  a2  s  . c o  m
    try {
        versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return versionCode;
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    try {// ww  w.j  a  va  2s.c o m
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        return pi.versionName;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static PackageInfo getPackageInfo(Context context) {
    PackageInfo info = null;// ww  w .java  2s  .  c om
    try {
        String packageName = context.getPackageName();
        info = context.getPackageManager().getPackageInfo(packageName, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return info;
}

From source file:Main.java

private static String getVersion(Context context) {
    String version = null;//from   w  ww . j  av  a2 s .  c  o m
    try {
        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        version = pInfo.versionName;
    } catch (NameNotFoundException e1) {

    }
    return version;
}

From source file:Main.java

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

From source file:Main.java

public static String getCurrentVersion(final Context context) {
    try {/*from w  ww . java 2  s  .  c  o  m*/
        final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        return "";
    }
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageInfo info = null;/*from w w w .  ja va 2s.  c o  m*/
    try {
        info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return info.applicationInfo.name;
    } catch (NameNotFoundException e) {
        return null;
    }

}