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

/**
 * Gets the resource id from the name and type
 * ex... getResIdFromIdentifier(ctx, "error_msg", "string");
 * @param context//from w w w .ja v a 2  s .  c  o  m
 * @param name
 * @param defType
 * @return resourceId
 */
public static int getResIdFromIdentifier(@NonNull Context context, String name, String defType) {
    return context.getResources().getIdentifier(name, defType, context.getPackageName());
}

From source file:Main.java

public static String getAppVersionName(Context context) {
    try {//  w w  w  . j ava2  s .co  m
        PackageInfo localPackageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return localPackageInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static int getVersionCode(Context context) {
    int verCode = -1;
    try {/* w  w  w .  ja va2  s. co  m*/
        verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return verCode;
}

From source file:Main.java

public static String getApplicationVersion(Context context) {
    try {/*from   ww  w .ja va  2s.  c o m*/
        return context.getApplicationContext().getPackageManager().getPackageInfo(context.getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        Log.e("NameNotFoundException", e.getMessage());
    }
    return "";
}

From source file:Main.java

public static Bitmap getApplicationIcon(Context context) {
    Drawable icon = null;/* w w w . j  ava 2 s  . co m*/
    final String packageName = context.getPackageName();

    try {
        icon = context.getPackageManager().getApplicationIcon(packageName);
        Bitmap b = drawableToBitmap(icon);
        return b; //Bitmap.createScaledBitmap(b, 120, 120, false);
    } catch (PackageManager.NameNotFoundException e) {
        //e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static int getVerCode(Context context) {
    int verCode = -1;
    try {/*  ww w .java 2s.  c  o  m*/
        verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return verCode;
}

From source file:Main.java

public static int getVersionCode(Context context) {
    int verCode = -1;
    try {/*from   ww w  .  j  a v a  2  s  .  c  o  m*/
        verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {

    }
    return verCode;
}

From source file:Main.java

/**
 * @param context/*from   ww  w  . ja v a2  s  .c o m*/
 * @param name
 * @return
 */
public static int getImageResourceId(Context context, String name) {
    try {
        return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}

From source file:Main.java

public static List<String> getsAvalibleAppsPackages(Context context) {
    if (sAvalibleAppsPackages.isEmpty()) {
        sAvalibleAppsPackages.add(context.getPackageName());
        sAvalibleAppsPackages.add(getCallerPackageName(context));
        sAvalibleAppsPackages.add("com.android.incallui");
        sAvalibleAppsPackages.add(getLauncherPackageName(context));
    }//from w  ww . jav a 2  s .co m
    return sAvalibleAppsPackages;
}

From source file:Main.java

public static int getAppVersionCode(Context context) {
    int verCode = -1;
    try {/* w ww .j  a v  a2 s  .  c om*/
        verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
    }
    return verCode;
}