How to get main applicationId inside code in the l

2019-07-03 18:45发布

问题:

I have library module where I'd like to starService through Intent(String). When I set:

Intent intent1 = new Intent(BuildConfig.APPLICATION_ID + ".REFRESH_DATA");

My BuildConfig.APPLICATION_ID is a library package. I need a variable in my code which will be populated with the main app package.

回答1:

Just use context.getPackageName().

https://developer.android.com/studio/build/application-id#change_the_package_name