获取第 3 方应用的清单文件 [英] Get manifest file for a 3rd party app
本文介绍了获取第 3 方应用的清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个应用程序允许您浏览应用程序的清单文件.它是如何做到的?我在操作系统的 API 中找不到任何用于获取另一个应用程序清单文件的内容.
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.
推荐答案
首先,您可以像这样获取应用程序列表:
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
);
然后可以从以下位置获取APK的位置:
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
从那里可以像这样从 .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();
}
最重要的是,不需要 root
Best of all, root is not required
这篇关于获取第 3 方应用的清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文