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

/**
 * Launch Application Setting to grant permission.
 *///from w ww.  j a  v a  2s. co  m
public static void launchPermissionSettings(Activity activity) {
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.setData(Uri.fromParts("package", activity.getPackageName(), null));
    activity.startActivity(intent);
}

From source file:Main.java

public static void printKeyHash(Activity pActivity) {
    // Add code to print out the key hash
    try {/*from   ww  w . ja  va 2s . com*/
        PackageInfo info = pActivity.getPackageManager().getPackageInfo(pActivity.getPackageName(),
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.d("KeyHash:", e.toString());
    } catch (NoSuchAlgorithmException e) {
        Log.d("KeyHash:", e.toString());
    }
}

From source file:Main.java

public static int getColor(Activity activity, String attr, int fallbackColor) {
    TypedValue color = new TypedValue();
    try {/*from   w w w .  j a va  2  s.c o  m*/
        int colorId = activity.getResources().getIdentifier(attr, "attr", activity.getPackageName());
        if (activity.getTheme().resolveAttribute(colorId, color, true)) {
            return color.data;
        }
    } catch (Exception ignored) {
    }

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

From source file:Main.java

public static int getVersionCode(Activity context) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packInfo = null;/*w  ww.  j  a  va 2 s.c o m*/
    try {
        packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (packInfo != null) {
        return packInfo.versionCode;
    }
    return 0;
}

From source file:Main.java

public static String getResourceString(String recourceName, Activity context) {
    Class rStringClass = null;/* w  w  w  . j av a2 s . com*/
    try {
        if (rStringClass == null) {
            rStringClass = Class.forName(
                    new StringBuilder().append(context.getPackageName()).append(".R$string").toString());
        }
        return context.getResources()
                .getString(((Integer) rStringClass.getDeclaredField(recourceName).get(null)).intValue());
    } catch (Exception e) {
        Log.e(context.getPackageName(), e.getMessage(), e);
        context.finish();
    }
    return "";
}

From source file:com.github.fi3te.iliasdownloader.view.Eula.java

private static PackageInfo getPackageInfo(Activity activity) {
    PackageInfo pi = null;/*from   w  w w. ja  v  a 2  s.  c o m*/
    try {
        pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_ACTIVITIES);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return pi;
}

From source file:Main.java

public static String getApplicationName(Activity context) {
    PackageManager packageManager = null;
    ApplicationInfo applicationInfo = null;
    try {/*from   www .  j a  v a2  s .c  o m*/
        packageManager = context.getPackageManager();
        applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        applicationInfo = null;
    }
    return (String) packageManager.getApplicationLabel(applicationInfo);
}

From source file:com.gudong.appkit.utils.Utils.java

public static boolean isOwnApp(Activity activity, String packageName) {
    return activity.getPackageName().equals(packageName);
}

From source file:Main.java

public static View getActionBarView(Activity activity) {
    Window window = activity.getWindow();
    View v = window.getDecorView();
    //      int resId = activity.getResources().getIdentifier("action_bar_container", "id", "android");
    int resId = activity.getResources().getIdentifier("action_bar_container", "id", activity.getPackageName());
    return v.findViewById(resId);
}

From source file:io.hypertrack.sendeta.util.PermissionUtils.java

public static void openSettings(Activity activity) {
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
    intent.setData(uri);// ww  w . j  a  v a  2  s  .c  om
    activity.startActivity(intent);
}