2

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.
}

1 Answer 1

2

For the package name just use the Context:

ctx.getPackageName()

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.