3

Can someone please tell me how to get the package name of the app module?

I know about context.getPackageName() method, but it returns the application id and not the actual package name (set in AndroidManifest).

Reason why I'm looking into this : Need to find out the application's R class at runtime from my library module and the R class is generated with the package defined in AndroidManifest's package_name.

If there is any other way to get the app module's R class, please share that as well.

avin
  • 459
  • 5
  • 14
  • why dont you use package name as application id? – Jyoti JK Mar 24 '18 at 11:47
  • There are multiple `R` classes, such as from libraries that might be used by that module. You are welcome to see if [`packageName` on `PackageInfo`](https://developer.android.com/reference/android/content/pm/PackageInfo.html#packageName) has what you want. That being said, I **strongly** recommend that you provide other means by which the library consumer can provide to you the resource IDs that your app needs (e.g., theme attributes, setters, constructor parameters, callbacks). – CommonsWare Mar 24 '18 at 11:56
  • Thanks for the quick response. Is there any other way I can achieve this without asking for the same from the library-consumer? as packageName on PackageInfo is not giving me what I want. Its returning the application id. – avin Mar 24 '18 at 12:01
  • try this out https://stackoverflow.com/a/48009287 – krishank Tripathi Mar 24 '18 at 12:03

0 Answers0