How to read a AndroidManifest.xml (in binary) file?
I am trying to read the content of the AndroiadManifest.xml file which seems to be in "DBase 3 da开发者_Go百科ta file" binary format.
Is there any code example in Java on how to read this binary file? I don't need write, just read the text content.
Step 1: First you need to extract .apk file using apktool
Step 2: Now we want to read the androidmanifest.xml file using Java DOM XML parser ex. want to read "uses-permission" tag form a 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) {
}
}
}
精彩评论