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.