Get manifest file for a 3rd party app

落花浮王杯 提交于 2019-12-25 03:48:17

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/25473904/get-manifest-file-for-a-3rd-party-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!