Example usage for android.content Context getApplicationInfo

List of usage examples for android.content Context getApplicationInfo

Introduction

In this page you can find the example usage for android.content Context getApplicationInfo.

Prototype

public abstract ApplicationInfo getApplicationInfo();

Source Link

Document

Return the full application info for this context's package.

Usage

From source file:Main.java

public static String getAbsolutePathOnExternalStorage(final Context pContext, final String pFilePath) {
    return Environment.getExternalStorageDirectory() + "/Android/data/"
            + pContext.getApplicationInfo().packageName + "/files/" + pFilePath;
}

From source file:Main.java

public static String getSystemVersionName(Context context) {
    String versionName = "";
    try {/*from   w  w  w  .j a v  a2s.  c  om*/
        versionName = context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName,
                0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionName;
}

From source file:org.stenerud.kscrash.KSCrashInstallationEmail.java

private static String getDefaultSubject(Context context) {
    return context.getApplicationInfo().processName + " has crashed";
}

From source file:org.stenerud.kscrash.KSCrashInstallationEmail.java

private static String getDefaultMessage(Context context) {
    return context.getApplicationInfo().processName + " has crashed.\nReports are attached to this email.";
}

From source file:Main.java

public static String getAppLabel(Context context) {
    if (context == null) {
        return null;
    }/*  w w  w  . j a  v  a 2  s. com*/

    return context.getPackageManager().getApplicationLabel(context.getApplicationInfo()).toString();
}

From source file:Main.java

/**
 * Gets resource boolean from values xml without relying on generated R.java. This allows to
 * compile the donations lib on its own, while having the configuration xml in the main project.
 * /*from w  ww. jav  a 2s .  co  m*/
 * @param name
 * @param context
 * @return
 */
public static boolean getResourceBoolean(Context context, String name) {
    int nameResourceID = context.getResources().getIdentifier(name, "bool",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource boolean found with name " + name);
    } else {
        return context.getResources().getBoolean(nameResourceID);
    }
}

From source file:Main.java

/**
 * Gets resource string from values xml without relying on generated R.java. This allows to
 * compile the donations lib on its own, while having the configuration xml in the main project.
 * //from w  w w  .  j a  va  2  s . com
 * @param name
 * @param context
 * @return
 */
public static String getResourceString(Context context, String name) {
    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource string found with name " + name);
    } else {
        return context.getString(nameResourceID);
    }
}

From source file:Main.java

/**
 * Gets resource string-array from values xml without relying on generated R.java. This allows
 * to compile the donations lib on its own, while having the configuration xml in the main
 * project.//from www. ja  va 2  s  . co  m
 * 
 * @param name
 * @param context
 * @return
 */
public static String[] getResourceStringArray(Context context, String name) {
    int nameResourceID = context.getResources().getIdentifier(name, "array",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource string-array found with name " + name);
    } else {
        return context.getResources().getStringArray(nameResourceID);
    }
}

From source file:Main.java

public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError {

    ApplicationInfo appInfo = appContext.getApplicationInfo();

    String pkg = appContext.getPackageName();
    int uid = appInfo.uid;
    Class appOpsClass = null;/*w  w  w .ja v  a 2s .  c  o  m*/
    Object appOps = appContext.getSystemService("appops");

    try {

        appOpsClass = Class.forName("android.app.AppOpsManager");

        Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
                String.class);

        Field opValue = appOpsClass.getDeclaredField(appOpsServiceId);

        int value = (int) opValue.getInt(Integer.class);
        Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg);

        return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED

    } catch (ClassNotFoundException e) {
        throw new UnknownError("class not found");
    } catch (NoSuchMethodException e) {
        throw new UnknownError("no such method");
    } catch (NoSuchFieldException e) {
        throw new UnknownError("no such field");
    } catch (InvocationTargetException e) {
        throw new UnknownError("invocation target");
    } catch (IllegalAccessException e) {
        throw new UnknownError("illegal access");
    }

}

From source file:Main.java

/**
 * @return null if not existing/*from  www  .j av a 2  s  .c  o m*/
 */
public static String getResourceString(Context context, String name) {

    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);

    if (nameResourceID == 0) {
        return null;
    } else {
        return context.getString(nameResourceID);
    }
}