Dave
Dave

Reputation: 107

Android Library - determine which package is being used

I have an Android Library (e.g. libA) that is referenced by two packages, com.siteA.appA and com.siteB.appB.

This works fine, but I want to modify the behaviour of the library based on the package (e.g. appB could display ads).

Is there way I can determine which package is using the Library from the library?

E.g. within LibA

if(package == "com.siteA.appA"){

   // Don't display adverts

}else{

  // Display adverts.
}

Upvotes: 2

Views: 283

Answers (1)

Macarse
Macarse

Reputation: 93143

For the package name just use the Context:

ctx.getPackageName()

If you need more info, you will need to use PackageManager.

Upvotes: 2

Related Questions