How to get Android application id?

android

Solution

If your are looking for the value defined by `applicationId` in gradle, you can simply use

BuildConfig.APPLICATION_ID 

EDIT 2022:

As indicated in the comments, `BuildConfig.APPLICATION_ID` is deprecated, but for librairies only. In this case, `BuildConfig.LIBRARY_PACKAGE_NAME` should be used instead, as explained here.

Also, now, `Context::getPackageName` returns the value defined by `applicationId` in gradle, even if you have several flavors with different `applicationId` (with a unique namespace), see here.

Problem

In Android, how do I get the application's id programatically (or by some other method), and how can I communicate with other applications using that id?

Original source

Related problems