[英]How to read a AndroidManifest.xml (in binary) file?
我正在嘗試讀取似乎是“DBase 3 數據文件”二進制格式的 AndroiadManifest.xml 文件的內容。
Java 中是否有關於如何讀取此二進制文件的代碼示例? 我不需要寫,只需閱讀文本內容。
第 1 步:首先您需要使用 apktool 提取.apk 文件
第 2 步:現在我們要使用 Java DOM XML 解析器讀取 androidmanifest.xml 文件。 想從 androidmanifest.xml 中讀取“uses-permission”標簽
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) {
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.