【问题标题】:Android : what is canonical package name?Android:什么是规范的包名?
【发布时间】:2013-01-13 14:26:03
【问题描述】:

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

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

【问题讨论】:

    标签: android android-package-managers


    【解决方案1】:

    这里是开发者文档:

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

    public abstract String[] currentToCanonicalPackageNames(String[] 名称)

    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[] 名称)

    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

    【讨论】:

    • yes :) 但是规范的包名到底代表什么?当前和规范包名称之间有什么区别?何时/何地使用它?我在 developer.android.com 上没有找到答案
    • 谢谢,但这些链接仍然不能回答我的问题。 (另一个 StackOverflow 问题只是简单地展示了如何获取这些规范名称,并且来源甚至没有文档。但是它们都没有说明这些规范名称到底是什么,它们的目的是什么等)。
    • 我知道这是一个非常古老的问题,但我只是想指出 Google 自己使用“getCanonicalName()”作为一个例子来说明什么是规范名称是好的.在这里查看他们的风格指南:google.github.io/styleguide/…
    • @AbeFehr 拥有更多新信息总是很棒。
    猜你喜欢
    • 2014-05-11
    • 1970-01-01
    • 2016-10-12
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2021-09-17
    相关资源
    最近更新 更多