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 boolean doesPackageHaveSameSignature(Context context, String productPackage) {
    int compareSignatures = context.getPackageManager().checkSignatures(context.getPackageName(),
            productPackage);/* w  w w . jav  a2s  . co m*/
    return PackageManager.SIGNATURE_MATCH == compareSignatures;
}

From source file:Main.java

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

From source file:Main.java

public static String getVersionName(Context context) {
    try {//w w w .j  a v  a 2s  . co  m
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static boolean isDefaultDialer(Context context) {
    final boolean result = TextUtils.equals(context.getPackageName(),
            getTelecomManager(context).getDefaultDialerPackage());
    if (result) {
        sWarningLogged = false;//from   w  w w  .j av a  2s.  c  o  m
    } else {
        if (!sWarningLogged) {
            // Log only once to prevent spam.
            Log.w(TAG, "Dialer is not currently set to be default dialer");
            sWarningLogged = true;
        }
    }
    return result;
}

From source file:Main.java

public static String[] getVersionName(Context mContext) throws Exception {
    String[] version = new String[2];
    String pkName = mContext.getPackageName();
    try {/*from  www .j  ava 2s.  c  o m*/
        PackageInfo pi = mContext.getPackageManager().getPackageInfo(pkName, 1);
        version[0] = pi.versionName;
        version[1] = pi.versionCode + "";
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return version;
}

From source file:Main.java

public static int getResIdByName(Context context, String resName) {
    Resources res = context.getResources();
    final String packageName = context.getPackageName();
    int imageResId = res.getIdentifier(resName, "drawable", packageName);
    return imageResId;
}

From source file:Main.java

public static int getResDraw(Context paramContext, String paramString) {
    return paramContext.getResources().getIdentifier(paramString, "drawable", paramContext.getPackageName());
}

From source file:Main.java

public static int getAppVersion(Context context) {
    try {//from  w  w w. j a  va2 s.co m
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);

        return info.versionCode;

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return 1;
}

From source file:Main.java

public static String readKey(Context context, String keyName) {
    try {/*from ww w .j a  va2 s  .c  o  m*/
        return context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).metaData.getString(keyName);
    } catch (PackageManager.NameNotFoundException e) {
        return "Android";
    }
}

From source file:Main.java

public static void putInt(Context context, String key, int value) {
    if (sp == null) {
        sp = context.getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
    }/* w w  w  . java 2  s . com*/
    SharedPreferences.Editor editor = sp.edit();
    editor.putInt(key, value);
    editor.commit();
}