Reading android manifest file

后端 未结 2 805
心在旅途
心在旅途 2021-01-24 22:41

Is there any way we can read/parse android manifest file as we do it for files in raw folder as mentioned here:

http://eagle.phys.utk.edu/guidry/android/writeSD.html

相关标签:
2条回答
  • 2021-01-24 23:24

    As already suggested, you can use the PackageManager for this purpose. There are several methods that are able to return one or more PackageInfo objects, which on their turn contain a public field ActivityInfo[] activities, provided you instruct it too... read below.

    The documentation mentions the following:

    Array of all tags included under , or null if there were none. This is only filled in if the flag GET_ACTIVITIES was set.

    So make sure that you provide that particular flag when requesting the info; e.g. when using getPackageInfo(...), do:

    getPackageInfo("your.package.name", PackageManager.GET_ACTIVITIES)
    

    If you need to retrieve more details, you can 'or' multiple flags together:

    getPackageInfo("your.package.name", PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS)
    

    Edit:

    Alternatively you could also use the getActivityInfo(android.content.ComponentName, int) and catch the NameNotFoundException that will be thrown if the requested Activity cannot be found, but generally this is considered 'abusing' exceptions.

    Anyways, up to you.

    0 讨论(0)
  • 2021-01-24 23:29

    [Edit after OP's comment] : You can use Android's PackageManaer http://developer.android.com/reference/android/content/pm/PackageManager.html to get information about the contents of the manifest file that Android understands.

    0 讨论(0)
提交回复
热议问题