3

Android's PackageManager class has currentToCanonicalPackageNames() and canonicalToCurrentPackageNames() methods. What exactly is canonical package name? Where is it used (what's its purpose)? When does it differ from a current package name?

For example, on my Nexus S the current package name for browser app is "com.google.android.browser", and its canonical name is the same "com.google.android.browser". For some other applications I've checked I also get same current and canonical package names. Neither developer.android.com, nor source code gives me an explanation of what exactly is canonical package name. Hope this helps to better understand what I'm asking above.

alexaschka
  • 433
  • 6
  • 14

1 Answers1

3

Here is developer documentation:

http://developer.android.com/reference/android/content/pm/PackageManager.html

public abstract String[] currentToCanonicalPackageNames (String[] names)

Added in API level 8
Map from the current package names in use on the device to whatever the current canonical name of that package is.

Parameters
names   Array of current names to be mapped.
Returns
Returns an array of the same size as the original, containing the canonical name for each package.

public abstract String[] canonicalToCurrentPackageNames (String[] names)

Added in API level 8
Map from a packages canonical name to the current name in use on the device.

Parameters
names   Array of new names to be mapped.
Returns
Returns an array of the same size as the original, containing the current name for each package.

Check out this link of the source for a better understanding: https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/app/ApplicationPackageManager.java

And please refer to this StackOverflow question: how do i get canonical names of packages of deafult apps in Android

Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • yes :) but what exactly canonical package name stands for? what's the difference between current and canonical package names? when/where is it used? I haven't found the answer on the developer.android.com – alexaschka Jan 13 '13 at 18:47
  • thanks, but those links still do not answer my questions. (another StackOverflow question simply shows how to get those canonical names, and the sources don't even have docs. But none of them tells what exactly are those canonical names, what's their purpose, etc). – alexaschka Jan 14 '13 at 09:41
  • I know that this is a very old question, but I just wanted to point out that Google themselves used "getCanonicalName()" as an example for where it would be good to document what a canonical name is. Check it out in their style guide here: http://google.github.io/styleguide/javaguide.html#s7.3.1-javadoc-exception-self-explanatory – Abe Fehr Jul 29 '15 at 19:28
  • @AbeFehr It is always great to have more and new information. – Jared Burrows Jul 29 '15 at 21:09