I need read the content of apk
file (including AndroidManifest.xml
) programmatically. I know there are some tools like apktool
, dex2jar
, aapt
to extract apk content but, I need to do the same through an Android application. By the way my start point is a valid apk file path.
Asked
Active
Viewed 5,374 times
5

Adrian Cid Almaguer
- 7,815
- 13
- 41
- 63

talha06
- 6,206
- 21
- 92
- 147
-
Is it like listing the information of the .apk or all the class files inside that ? Make It Clear. – Nayan Rath Feb 22 '14 at 13:21
-
@NayanRath I need to read both `AndroidManifest.xml` and `source files`. – talha06 Feb 22 '14 at 13:23
-
Is this needed for Virus Scanning.Just Asking Coz i am also doing the same and having some issues. – Nayan Rath Feb 22 '14 at 13:29
-
I will look for issues and let You know !!! – Nayan Rath Feb 22 '14 at 13:39
-
something like it, I'm working on an advanced APK Inspector.. Thanks for your care.. @NayanRath – talha06 Feb 22 '14 at 14:20
2 Answers
4
See this answer on another question: https://stackoverflow.com/a/34850406/55940
Basically you can use this:
PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(file.getAbsolutePath(), 0);
This would only get the meta data though... You would have to use a ZipInputStream etc to read the content of the file.

Daverix
- 399
- 2
- 16
3
First of all get the apk file from its path by this code
final PackageManager pm = getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo("PACKAGE NAME HERE", PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File file = new File(packageInfo.applicationInfo.sourceDir);
Uri uri = Uri.fromFile(file);

Nitin Misra
- 4,472
- 3
- 34
- 52
-
after I get uri from file, how can I read apk content (i.e. manifest file, etc..)? – talha06 Feb 22 '14 at 14:08
-
you could read this thread http://stackoverflow.com/questions/2097813/how-to-parse-the-androidmanifest-xml-file-inside-an-apk-package/4761689#4761689 and this also http://stackoverflow.com/questions/13469147/get-android-apk-file-versionname-or-versioncode-without-installing-apk – Nitin Misra Feb 22 '14 at 14:13
-
-
no, it works for installed applications because it uses `PackageManager`. – talha06 Feb 22 '14 at 14:44