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 getApplicationName(final Context context) {
    final ApplicationInfo applicationInfo = context.getApplicationInfo();
    return context.getString(applicationInfo.labelRes);
}

From source file:Main.java

/**
 * Determines if the application has been compiled with debugging enabled.
 *
 * @param context {@link Context} used to access the {@link ApplicationInfo}.
 *
 * @return true if debugging is enabled, otherwise false.
 *///from  w w  w .  j a va  2 s  .c  o m
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isDebuggable(final Context context) {
    return context == null || context.getApplicationInfo() == null
            || (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));

}

From source file:Main.java

public static String getAppName(Context mContext) {
    PackageManager pm = mContext.getPackageManager();
    return mContext.getApplicationInfo().loadLabel(pm).toString();
}

From source file:Main.java

public static boolean isDebug(Context ctx) {

    boolean isDebuggable;
    isDebuggable = (0 != (ctx.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
    // System.out.println( "isDebug : " + isDebuggable);
    return isDebuggable;
}

From source file:Main.java

/**
 * Judge whether an app is dubuggable//from  w  ww.j ava2s.  c  o m
 *
 * @param context
 * @return
 */
public static boolean isApkDebuggable(Context context) {
    try {
        ApplicationInfo info = context.getApplicationInfo();
        return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    } catch (Exception e) {

    }
    return false;
}

From source file:Main.java

public static String getAppName(Context context) {
    PackageManager pm = context.getPackageManager();
    String appName = context.getApplicationInfo().loadLabel(pm).toString();
    return appName;
}

From source file:Main.java

public static Object loadClass(Context context, String path) {
    try {//ww w  .  j  a  v  a  2 s .  co  m
        String dexPath = context.getApplicationInfo().sourceDir;
        PathClassLoader pathClassLoader = new PathClassLoader(dexPath, context.getClassLoader());
        Class<?> c = Class.forName(path, true, pathClassLoader);
        Object ret = c.newInstance();
        return ret;
    } catch (InstantiationException ex1) {
        ex1.printStackTrace();
    } catch (IllegalAccessException ex2) {
        ex2.printStackTrace();
    } catch (ClassNotFoundException ex3) {
        ex3.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static CharSequence getApplicationName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return context.getApplicationInfo().loadLabel(packageManager);
}

From source file:Main.java

public static File getSharedPreferencesFile(Context context, String prefFilename) {
    final ApplicationInfo applicationInfo = context.getApplicationInfo();
    if (applicationInfo == null)
        return null;
    if (applicationInfo.dataDir == null)
        return null;
    final File dataDir = new File(applicationInfo.dataDir);
    final File sharedPrefsDir = new File(dataDir, "shared_prefs");

    final String filename = prefFilename == null ? applicationInfo.packageName + "_preferences.xml"
            : prefFilename;//from w ww . j  av  a 2  s  . com
    final File sharedPrefFile = new File(sharedPrefsDir, filename);
    return sharedPrefFile.exists() && sharedPrefFile.isFile() ? sharedPrefFile : null;
}

From source file:Main.java

public static CharSequence getApplicationLabel(Context context) {
    PackageManager pm = context.getPackageManager();
    ApplicationInfo info = context.getApplicationInfo();
    CharSequence appLabel = pm.getApplicationLabel(info);
    return appLabel;
}