Java – How do I read AndroidManifest.xml (binary) files?

How do I read AndroidManifest.xml (binary) files?… here is a solution to the problem.

How do I read AndroidManifest.xml (binary) files?

I’m trying to read the contents of an AndroiadManifest.xml file, which appears to be in “DBase 3 data file” binary format.

Is there a code example in Java on how to read this binary? I don’t need to write, just read the text content.

Solution

Step 1: First you need to extract the .apk file using apktool

Step 2: Now we want to read the androidmanifest.xml file using the Java DOM XML parser
Predecessor. You want to read the “uses-permission” tag from AndroidManifest.xml

public class parse_xml 
  {
    public static void main(String argv[]) 
    {
    try {
    File fXmlFile= new File("C:\\apkfolder\\AndroidManifest.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();
    System.out.println("Root element :"+ doc.getDocumentElement().getNodeName());
    NodeList nList= doc.getElementsByTagName("uses-permission");
    System.out.println("----------------------------");
    for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        System.out.println("\nCurrent Element :" + nNode.getNodeName());
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;

System.out.println(eElement.getAttribute("android:name"));

}

}
       System.out.println("total no. of permissions"+ nList.getLength());
    } catch (Exception e) {
    }
  }
}

Related Problems and Solutions