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 String getResourceString(String paramString, Activity paramActivity) {
    Class localClass = null;/*from www . j a v a  2 s .  c om*/
    if (0 == 0)
        ;
    try {
        localClass = Class.forName(paramActivity.getPackageName() + ".R$string");
        String str = paramActivity.getResources()
                .getString(((Integer) localClass.getDeclaredField(paramString).get(null)).intValue());
        return str;
    } catch (Exception localException) {
        Log.e(paramActivity.getPackageName(), localException.getMessage(), localException);
        paramActivity.finish();
    }
    return "";
}

From source file:Main.java

/**
 * Get application version.//  w ww  . ja v a2  s. co  m
 *
 * @param activity
 *          current activity.
 * @return application version. This equals to the version that appears in
 *         settings->application.
 * @throws android.content.pm.PackageManager.NameNotFoundException
 */
public static String getAppVersion(Activity activity) throws PackageManager.NameNotFoundException {
    PackageManager pm = activity.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(activity.getPackageName(), 0);
    return pi.versionName;
}

From source file:Main.java

public static int getDrawableId(final Activity context, final String drawableName) {
    final int resId = context.getResources().getIdentifier(drawableName, "drawable", context.getPackageName());
    return resId;
}

From source file:Main.java

public static void openApplicationSettings(Activity activity) {
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
    intent.setData(uri);//from w  ww .ja  v  a 2s.  co m
    activity.startActivity(intent);
}

From source file:Main.java

/**
 * Get application name.//from  w ww.j  a v a 2s  . co  m
 *
 * @param activity
 *          current activity.
 * @return application name. This equals to the app title that appears in
 *         settings->application.
 * @throws android.content.pm.PackageManager.NameNotFoundException
 */
public static String getAppName(Activity activity) throws PackageManager.NameNotFoundException {
    PackageManager pm = activity.getPackageManager();
    ApplicationInfo appInfo = pm.getApplicationInfo(activity.getPackageName(), 0);
    return pm.getApplicationLabel(appInfo).toString();
}

From source file:Main.java

public static int findByValue(Activity activity, String value) {
    value = value.replaceAll("\\D", "_");
    value = "day_" + value;

    int id = activity.getResources().getIdentifier(value, "color", activity.getPackageName());

    int idColor = (id == 0) ? R.color.darker_gray : id;

    return activity.getResources().getColor(idColor);
}

From source file:Main.java

public static View findViewInList(Activity activity, ListView list, int index, String string) {
    View view = getViewInList(list, index);
    return view.findViewById(view.getResources().getIdentifier(string, "id", activity.getPackageName()));
}

From source file:Main.java

public static String GetAppName(Activity act) {
    final PackageManager pm = act.getApplicationContext().getPackageManager();

    ApplicationInfo ai;/*from  w ww.  j a va 2s  . c o  m*/
    try {
        ai = pm.getApplicationInfo(act.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "unknown");
    return applicationName;
}

From source file:Main.java

public static String getVersionName(Activity ctx) {
    PackageManager packageManager = ctx.getPackageManager();
    PackageInfo packInfo = null;/*  w w w  .jav  a 2s .  co m*/
    try {
        packInfo = packageManager.getPackageInfo(ctx.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    String version = packInfo.versionName;
    return version;
}

From source file:Main.java

public static String getVersionName(Activity activity) {
    PackageManager packageManager = activity.getPackageManager();
    PackageInfo packInfo;//from  www . ja v a  2s . c om
    try {
        packInfo = packageManager.getPackageInfo(activity.getPackageName(), 0);
        return packInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "1.0";
    }
}