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.
Viewing the contents of an APK file: Since APK files come in compressed ZIP format, any ZIP decompression tool can open it. So, for viewing the contents of an APK file, all you have to do is rename its extension to . zip and open it. Or, you can open it directly through an open dialogue box of a zip application.
Expand com folder and then expand Package name folder you will get all the java files. 10.To open Manifest file and resources just open them in android studio. In this manner we can extract source code in just 10 simple steps.
Scanning the APK To use, do the following: Open the site. Click on Choose File, and in the browser dialogue box, select your file. Click on Scan it! to get your results.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With