Android:什么是规范包名?

时间:2013-01-13 14:26:04

标签: android android-package-managers

Android的PackageManager类有currentToCanonicalPackageNames()和canonicalToCurrentPackageNames()方法。规范包名究竟是什么?它在哪里使用(它的目的是什么)?它何时与当前包名称不同?

例如,在我的Nexus S上,浏览器应用的当前包名称为“com.google.android.browser”,其规范名称与“com.google.android.browser”相同。对于我检查过的其他一些应用程序,我也获得了相同的当前和规范包名称。 developer.android.com和源代码都没有给我解释什么是规范的包名。希望这有助于更好地理解我上面提出的问题。

1 个答案:

答案 0 :(得分:4)

这是开发者文档:

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.

查看来源的链接以便更好地理解: https://android.googlesource.com/platform/frameworks/base/+/483f3b06ea84440a082e21b68ec2c2e54046f5a6/core/java/android/app/ApplicationPackageManager.java

请参阅此StackOverflow问题:how do i get canonical names of packages of deafult apps in Android