Eva
Eva

Reputation: 332

How can I analyse a Apk file in android application? Get the permissions

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

Answers (1)

Toumash
Toumash

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

Related Questions