Reputation: 332
I want to write an android app which can analyse the APK file and output the permissions this application required? I saw some app achieve this and can anyone tell me which method they might used? thanks
Upvotes: 0
Views: 2997
Reputation: 1087
The best way of doing it with external apk files, not the installed ones:
The .apk
file is a casual .zip
with changed extension. The permissions are located in AndroidManifest.xml
file, so your job is to load it into memory, parse with some XML parser and search for uses-permission
tag.
It looks like this <uses-permission android:name="android.permission.XXX"/>
.
To unzip the xml from Archive i would recommend This SO post
You should modify it to grab only the .xml file, and
Documentation of ZipEntry is telling that it has a .getName()
method.
I will leave the xml-parsing research for you (that tutorial is not bad), and yes, its obviously possible.
EDIT: I found one library that could possibly do it - APK-Parser Github, but it was not tested on android. Some users are reporting some issues on android L
try(ApkParser apkParser = new ApkParser(new File(filePath))) {
for (String permission: apkMeta.getUsesPermissions()) {
Log.d("APK PERM",permission);
}
}
Upvotes: 2