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 boolean isDebuggable(Context context) {
    if (context == null) {
        return false;
    }// ww w.j  ava  2s  .c  o  m
    return (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
}

From source file:Main.java

public static List<String> getPackageAllClassName(Context context, String packageName) throws IOException {
    String sourcePath = context.getApplicationInfo().sourceDir;
    List<String> paths = new ArrayList<>();

    if (sourcePath != null) {
        DexFile dexfile = new DexFile(sourcePath);
        Enumeration<String> entries = dexfile.entries();

        while (entries.hasMoreElements()) {
            String element = entries.nextElement();
            if (element.contains(packageName)) {
                paths.add(element);//from w w w.jav  a2s .  com
            }
        }
    }

    return paths;
}

From source file:Main.java

public static boolean isDebug(Context context) {
    if (sIsDebug == null && context != null) {
        final ApplicationInfo info = context.getApplicationInfo();
        if (info != null)
            sIsDebug = (info.flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    }/*from   w w  w.ja va2 s  .  c om*/

    return sIsDebug != null && sIsDebug;
}

From source file:Main.java

public static String getResourceString(String name, Context context) {
    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        throw new IllegalArgumentException("No resource string found with name " + name);
    } else {/*from ww  w .  j  ava  2 s. com*/
        return context.getString(nameResourceID);
    }
}

From source file:Main.java

public static String getResourceString(String name, Context context) {
    int nameResourceID = context.getResources().getIdentifier(name, "string",
            context.getApplicationInfo().packageName);
    if (nameResourceID == 0) {
        return ""; //throw new IllegalArgumentException("No resource string found with name " + name);
    } else {//from  w  w  w  .  java 2  s . co  m
        return context.getString(nameResourceID);
    }
}

From source file:Main.java

private static String getApkPath(Context context) {
    String apkPath = null;/*ww  w.jav  a  2  s  . c om*/
    try {
        ApplicationInfo applicationInfo = context.getApplicationInfo();
        if (applicationInfo == null) {
            return null;
        } else {
            apkPath = applicationInfo.sourceDir;
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return apkPath;
}

From source file:Main.java

/**
 * Get channel from META-INF directory./*w  ww. j a  va2  s .c o  m*/
 *
 * @return the channel name if success,otherwise return "none"
 */
public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    String ret = "";
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith("META-INF/channel")) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    String[] split = ret.split("_");
    if (split != null && split.length >= 2) {
        return ret.substring(split[0].length() + 1);

    } else {
        return "none";
    }
}

From source file:Main.java

public static void writeJsonOnDisk(Context context, String fileName, StringBuilder bigStr) {
    try {//from w w  w  .j a v a 2s.  com
        FileWriter Filewriter = new FileWriter(context.getApplicationInfo().dataDir + "/" + fileName + ".json");
        Filewriter.write(bigStr.toString());
        Filewriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    ZipFile zipfile = null;/*from w w w  . java 2 s  .c  o  m*/
    String ret = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith(FOLDER_NAME) && entryName.contains(CHANNEL_SCHEME)) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    try {
        if (ret != null) {
            String[] split = ret.split(CHANNEL_SCHEME_SPIT);
            if (split.length >= 2) {
                return ret.substring(split[0].length() + 1);
            }
        }
    } catch (Exception e) {

    }

    return null;
}

From source file:Main.java

public static List<String> getSharedPreferenceTags(Context context) {
    ArrayList<String> tags = new ArrayList<String>();

    String rootPath = context.getApplicationInfo().dataDir + "/shared_prefs";
    File root = new File(rootPath);
    if (root.exists()) {
        for (File file : root.listFiles()) {
            String fileName = file.getName();
            if (fileName.endsWith(PREFS_SUFFIX)) {
                tags.add(fileName.substring(0, fileName.length() - PREFS_SUFFIX.length()));
            }/*w w w. j  a  v  a2 s .com*/
        }
    }

    Collections.sort(tags);

    return tags;
}