Get manifest file for a 3rd party app

2019-09-11 07:19发布

This application allows you to browse applications' manifest files. How does it do that? I can't find anything in the OS's API for getting another application's manifest file.

2条回答
淡お忘
2楼-- · 2019-09-11 07:45

First, you can get a list of Applications like so:

PackageManager pm = getActivity().getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(
        PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES
    );

Then the location of the APK can be gotten from:

apps.get(x).publicSourceDir

The above will have a value such as:

/data/app/com.example.someonesapp.apk

From there the manifest file can be accessed from the .apk like so:

try {
    ZipFile apk = new ZipFile("/data/app/com.example.someonesapp.apk");
    ZipEntry manifest = apk.getEntry("AndroidManifest.xml");
    if (manifest != null){
        Log.d("ManifestGetter", "Manifest size = " + manifest.getSize());
        InputStream stream = apk.getInputStream(manifest);
        // do stuff with the file here e.g. get contents
        stream.close();
    }
    apk.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} 

Best of all, root is not required

查看更多
祖国的老花朵
3楼-- · 2019-09-11 07:58

The Manifest file is not hidden when you build you app. It's shipped inside your .apk file as-is. You can check this with an archiver, like 7zip. So just open your apk file with 7zip (it will recognize it) and you will see your AndroidManifest.xml file there.

That app, i assume, just looks for that file in the application folder.

查看更多
登录 后发表回答