For those who are using Gradle, as @Billda mentioned, you can get the package name via:
BuildConfig.APPLICATION_ID
This gives you the package name declared in your app gradle:
android {
defaultConfig {
applicationId "com.domain.www"
}
}
If you are interested to get the package name used by your java classes (which sometimes is different than applicationId
), you can use
BuildConfig.class.getPackage().toString()
If you are confused which one to use, read here:
Note: The application ID used to be directly tied to your code's package name; so some Android APIs use the term "package name" in their method names and parameter names, but this is actually your application ID. For example, the Context.getPackageName() method returns your application ID. There's no need to ever share your code's true package name outside your app code.