How to programmatically read the contents of an apk file?

I need to read the contents of a file apk(including AndroidManifest.xml) programmatically. I know that there are some tools, such as apktool, dex2jar, aaptto retrieve the contents apk, but I need to do the same through an Android app . By the way, my starting point is a valid apk file path .

+3
source share
2 answers

First of all, get the apk file from its path using 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);
0
source

See the answer to another question: fooobar.com/questions/301119 / ...

You can mainly use this:

PackageInfo packageInfo = context.getPackageManager().getPackageArchiveInfo(file.getAbsolutePath(), 0);

, ... ZipInputStream .., .

0

All Articles