如何在不使用 PackageManager 的情况下读取 Android Manifest?
我正在开发一个 Android 应用程序,它需要比 PackageManager
中提供的信息更多的信息(例如意图过滤器)。我创建了一个解析器来读取 AndroidManifest 文件,但我找不到任何已安装应用程序的 AndroidManifest.xml
的位置。我使用的代码是:
int flags = PackageManager.GET_ACTIVITIES
//| PackageManager.GET_CONFIGURATIONS
//| PackageManager.GET_DISABLED_COMPONENTS
//| PackageManager.GET_GIDS
//| PackageManager.GET_INSTRUMENTATION
//| PackageManager.GET_INTENT_FILTERS //Not needed (see BUG: http://code.google.com/p/android/issues/detail?id=3217)
| PackageManager.GET_META_DATA
| PackageManager.GET_PERMISSIONS
| PackageManager.GET_PROVIDERS
| PackageManager.GET_RECEIVERS
| PackageManager.GET_RESOLVED_FILTER
| PackageManager.GET_SERVICES
| PackageManager.GET_SHARED_LIBRARY_FILES
| PackageManager.GET_SIGNATURES
| PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_URI_PERMISSION_PATTERNS;
final PackageInfo pkg = pm.getPackageInfo(info.packageName, flags);
File manifest = new File(pkg.applicationInfo.publicSourceDir + "/AndroidManifest.xml");
if (manifest.exists()) {
//Code never reaches this point
}
根据文档, ApplicationInfo.publicSourceDir 是:
此内容公开部分的位置的完整路径 包(即主要资源包和清单)。为了 非前向锁定应用程序,这与 {@link #sourceDir) 相同。
我做错了什么,或者我该如何做正确的事情?
I am working on an Android application that requires more information than what is available in the PackageManager
(such as intent filters). I have created a parser for reading the AndroidManifest file, but I cannot find the location of the AndroidManifest.xml
for any installed application. The code I am using is:
int flags = PackageManager.GET_ACTIVITIES
//| PackageManager.GET_CONFIGURATIONS
//| PackageManager.GET_DISABLED_COMPONENTS
//| PackageManager.GET_GIDS
//| PackageManager.GET_INSTRUMENTATION
//| PackageManager.GET_INTENT_FILTERS //Not needed (see BUG: http://code.google.com/p/android/issues/detail?id=3217)
| PackageManager.GET_META_DATA
| PackageManager.GET_PERMISSIONS
| PackageManager.GET_PROVIDERS
| PackageManager.GET_RECEIVERS
| PackageManager.GET_RESOLVED_FILTER
| PackageManager.GET_SERVICES
| PackageManager.GET_SHARED_LIBRARY_FILES
| PackageManager.GET_SIGNATURES
| PackageManager.GET_UNINSTALLED_PACKAGES
| PackageManager.GET_URI_PERMISSION_PATTERNS;
final PackageInfo pkg = pm.getPackageInfo(info.packageName, flags);
File manifest = new File(pkg.applicationInfo.publicSourceDir + "/AndroidManifest.xml");
if (manifest.exists()) {
//Code never reaches this point
}
According to the documentation, ApplicationInfo.publicSourceDir is:
Full path to the location of the publicly available parts of this
package (i.e. the primary resource package and manifest). For
non-forward-locked apps this will be the same as {@link #sourceDir).
What am I doing wrong, or how can I do this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里是代码:
但是你需要解析它。
Here the code:
but then you need to parse it.
虽然花了很长时间,但我想通了。资产(例如清单)被压缩 - 请参阅 这篇文章。如果它没有被压缩,@gwa(或类似的东西)提供的代码就可以达到目的。
It took a long time, but I figured it out. Assets, such as the manifest, are compressed - see this post. If it had not been compressed, the code provided by @gwa (or something similar to it) would have done the trick.
我认为您的应用程序没有足够的权限来读取它。在已取得 root 权限的设备上尝试一下。
I don't think your app have enough privilege to read it. Try it on an rooted device.