Example usage for android.app Activity getPackageName

List of usage examples for android.app Activity getPackageName

Introduction

In this page you can find the example usage for android.app Activity getPackageName.

Prototype

@Override
    public String getPackageName() 

Source Link

Usage

From source file:Main.java

public static void scoreApp(Activity activity) {
    Uri uri = Uri.parse("market://details?id=" + activity.getPackageName());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    try {// w  w w .j  av a2  s. com
        activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static View findViewByIdString(Activity a, String s) {
    return a.findViewById(a.getResources().getIdentifier(s, "id", a.getPackageName()));
}

From source file:Main.java

public static View findActionBarContainer(Activity activity) {
    int id = activity.getResources().getIdentifier("action_bar_container", "id", activity.getPackageName());
    return activity.findViewById(id);
}

From source file:Main.java

public static int getVersionCode(Activity activity) {
    try {//w  w  w .ja v a2 s . com
        PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        return info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

public static String getVersion(Activity activity) {
    try {/*from  w w  w .j a v a  2 s  .c  o  m*/
        PackageInfo pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        return pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "0";
    }
}

From source file:Main.java

public static String getVersionName(Activity activity) {
    try {/* w  ww  .  jav  a2  s  .c om*/
        PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        return info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static void rateTheApp(Activity activity) {
    Intent goToMarket = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + activity.getPackageName()));
    activity.startActivity(goToMarket);//  w ww .  ja va  2 s  .co  m
}

From source file:Main.java

public static int getResIDByResName(Activity activity, String iconName) {
    Resources resources = activity.getResources();
    int indentify = resources.getIdentifier(activity.getPackageName() + ":drawable/" + iconName, null, null);
    return indentify;
}

From source file:Main.java

public static int getVersionNumber(Activity act) {

    int versionCode = -1;
    try {/* w  w  w .ja v a  2 s . c  o  m*/
        PackageInfo packageInfo = act.getPackageManager().getPackageInfo(act.getPackageName(), 0);
        versionCode = packageInfo.versionCode;
    } catch (Exception ex) {
        System.out.println("Version Num : " + ex);
    }
    return versionCode;
}

From source file:Main.java

public static String getBuildTimestamp(Activity activity) {
    String s = "";
    try {/* w  ww  .  ja v a  2s. c  o m*/
        ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        s = SimpleDateFormat.getInstance().format(new java.util.Date(time));
        zf.close();
    } catch (Exception e) {
    }
    return s;
}