How to get Android application id?

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?


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

BuildConfig.APPLICATION_ID 

If by application id, you're referring to package name, you can use the method Context::getPackageName (http://http://developer.android.com/reference/android/content/Context.html#getPackageName%28%29).

In case you wish to communicate with other application, there are multiple ways:

  1. Start an activity of another application and send data in the "Extras" of the "Intent"
  2. Send a broadcast with specific action/category and send data in the extras
  3. If you just need to share structured data, use content provider
  4. If the other application needs to continuously run in the background, use Server and "bind" yourself to the service.

If you can elaborate your exact requirement, the community will be able to help you better.


i'm not sure what "application id" you are referring to, but for a unique identifier of your application you can use:

getApplication().getPackageName() method from your current activity


For getting AppId (or package name, how some says), just call this:

But be sure that you importing BuildConfig with your app id packages path

BuildConfig.APPLICATION_ID 

Package name is your android app id .

String appId = BuildConfig.APPLICATION_ID

Or

https://play.google.com/store/apps/details?id=com.whatsapp

App Id = com.whatsapp