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 getAppVerCode(Context ctx) {
    try {//from  w  ww.  ja va 2  s  .  c o  m
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),
                PackageManager.GET_CONFIGURATIONS);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getAppVerName(Context ctx) {
    try {//from ww w.j  a  v  a 2s . c o m
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),
                PackageManager.GET_CONFIGURATIONS);
        return info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static int getAppVerCode(Context c) {
    try {//from w w w . j  ava  2 s .  c o  m
        PackageInfo packageInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        return packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        return 0;
    }
}

From source file:Main.java

public static String getAppVer(Context c) {
    try {/*w ww .j a  v  a2  s  .c  o  m*/
        PackageInfo packageInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
        return packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        return "";
    }
}

From source file:Main.java

public static String getVersionName(Context context) {
    try {/*ww w .  j  ava2 s  .  c  o  m*/
        PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return pi.versionName;
    } catch (NameNotFoundException e) {
        return null;
    }
}

From source file:Main.java

public static void remove(Context context, String key) {
    if (sp == null) {
        sp = context.getSharedPreferences(context.getPackageName(), Activity.MODE_PRIVATE);
    }/*from  ww  w. jav  a  2s. c o  m*/
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);
    editor.commit();
}

From source file:Main.java

public static boolean getStatusOfRenderResetSwitcher(Context context) {
    boolean flag;
    try {/*from   w w w.ja v  a 2 s  .  co m*/
        flag = context.getSharedPreferences(context.getPackageName(), 1).getBoolean("reset_default_render",
                false);
    } catch (Exception exception) {
        return false;
    }
    return flag;
}

From source file:Main.java

public static String getPackageName(Context ctx) {
    try {/*from   w  ww . j a  v a  2 s .  c  om*/
        PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        return info.packageName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

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

From source file:Main.java

public static Intent getSysAppDetailIntent(Context context) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName()));
}