- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
(或者是“包名”?)
从一个应用程序切换到另一个应用程序的一种方法是获取应用程序的启动 Intent ,这可以使用(给定一些 context
)来完成:
PackageManager manager = context.getPackageManager();
Intent intent = manager.getLaunchIntentForPackage(packageName);
请注意,参数名称称为 packageName
,甚至方法名称也提到“package”。但是,这不是包名!这是我们应该在这里使用的应用程序 ID!
例如,如果我有一个调试构建类型,而不是发布应用程序 ID com.example
具有调试后缀,例如它是 com.example.debug
,我必须使用 "com.example.debug"
作为 getLaunchIntentForPackage
的参数。但是应用程序的包命名空间保持不变 ( by default ):它仍然是 com.example
!如果我没有安装我的非调试应用程序,getLaunchIntentForPackage
方法返回 null
,因为应用程序 ID com.example
没有安装.
那我在看什么?我认为 com.example
是我的程序包名称,com.example.debug
是我的应用程序 ID。但是为什么 PackageManager#getLaunchIntentForPackage方法提到'package'和'package name',而会认为它应该提到'application ID'吗?
这只是 Android SDK 中错误命名的方法,还是我误解了什么?
我的问题基于以下信息。
Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
[...]
When you create a new project in Android Studio, the
applicationId
exactly matches the Java-style package name you chose during setup. However, the application ID and package name are independent of each other beyond this point. You can change your code's package name (your code namespace) and it will not affect the application ID, and vice versa (though, again, you should not change your application ID once you publish your app). However, changing the package name has other consequences you should be aware of, so see the section about modifying the package name.
因此,应用程序 ID 可以在 Play 商店中唯一标识您的应用程序。包名称是应用程序代码库中子包和类的命名空间。到目前为止一切顺利,我明白这一点。
然而,在本文档页面的末尾,我们有以下更令人困惑的亮点:
One more thing to know: Although you may have a different name for the manifest
package
and the GradleapplicationId
, the build tools copy the application ID into your APK's final manifest file at the end of the build. So if you inspect yourAndroidManifest.xml
file after a build, don't be surprised that thepackage
attribute has changed. Thepackage
attribute is where Google Play Store and the Android platform actually look to identify your app; so once the build has made use of the original value (to namespace theR
class and resolve manifest class names), it discards that value and replaces it with the application ID.
所以我们在一页上有多个矛盾!
从这个亮点来看,至少关于构建工具被应用程序覆盖包名称的说法似乎是不正确的,因为:
在应用 com.example.debug
中为 Activity com.example.MainActivity
创建 Intent 时,我必须指定 com.example.debug
作为应用程序 ID,com.example.MainActivity
作为组件名称。在运行时,组件名称并没有将其包名称更改为应用程序 ID,因此包 namespace 似乎没有被构建工具更改?
...有人可以通过各种示例创建一个很好的答案,这些示例显示应用程序 ID 和包(名称)何时相同,何时不同,以及 Android 系统和 Google Play 实际使用哪个。还请考虑一个具有库依赖项的示例:据我了解,库的包命名空间不会更改,但它会使用您的应用程序 ID 运行,对吗?
最佳答案
android:package
<manifest>
中的属性这就是我们在这里谈论的。它曾经被称为“包名”,在一些较旧的文档中仍然被称为“包名”。它不是 Java 包名,即使它看起来像一个包名,但它与源代码中的 Java 包名无关。
最近此属性被称为“应用程序 ID”,尤其是在与 Firebase、Play 商店等相关的文档中。
其实是一样的。 “包名”为“应用ID”。
引用https://developer.android.com/guide/topics/manifest/manifest-element.html#package
注意:
有一个地方可能会让人感到困惑,那就是 list 中组件名称的简写符号。例如:
<activity
android:name=".ui.activities.MainActivity">
</activity>
在这种情况下,android:name
属性指定“Activity
的完全限定 Java 类名”。但是,如果名称以句点开头(如本例所示),则应用程序的“程序包名称”(来自 android:package
标记的 <manifest>
属性)将添加到类的名称前面,以形成完全限定的 Java Activity
的类名.
如果您遇到 android:package
不同构建变体的属性已更改(如在包名称中使用 debug
的示例),您不应在 list 中使用组件名称的简写符号!您应始终使用完全限定名称,像这样:
<activity
android:name="com.mycompany.mypackage.ui.activities.MainActivity">
</activity>
关于android - 何时使用应用程序 ID 或程序包名称 a.k.a. PackageManager#getLaunchIntentForPackage 方法名称不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55222971/
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我们可以说 O(K + (N-K)logK)相当于O(K + N logK)对于 1 < = K <= N ? 最佳答案 简短的回答是它们不等价,这取决于k 的值。如果k等于N,那么第一个复杂度是O(
我有以下解决方案,但我从其他评论者那里听说它是 O(N * K * K),而不是 O(N * K)其中 N 是 K 列表的(最大)长度,K 是列表的数量。例如,给定列表 [1, 2, 3] 和 [4,
我试图理解这些语法结构之间的语义差异。 if ((i% k) == (l % k) == 0) 和 if ((i % k) == 0 && (l % k) == 0) 最佳答案 您的特定表达式((i
我有时会使用一维数组: A = np.array([1, 2, 3, 4]) 或 2D 阵列(使用 scipy.io.wavfile 读取单声道或立体声信号): A = np.array([[1, 2
在文档聚类过程中,作为数据预处理步骤,我首先应用奇异向量分解得到U、S和Vt 然后通过选择适当数量的特征值,我截断了 Vt,这让我从阅读的内容中得到了很好的文档-文档相关性 here .现在我正在对矩
我问的是关于 Top K 算法的问题。我认为 O(n + k log n) 应该更快,因为……例如,如果您尝试插入 k = 300 和 n = 100000000,我们可以看到 O(n + k log
这个问题与另一个问题R:sample()密切相关。 。我想在 R 中找到一种方法来列出 k 个数字的所有排列,总和为 k,其中每个数字都是从 0:k 中选择的。如果k=7,我可以从0,1,...,7中
我目前正在评估基于隐式反馈的推荐系统。我对排名任务的评估指标有点困惑。具体来说,我希望通过精确度和召回率来进行评估。 Precision@k has the advantage of not requ
我在 Python 中工作,需要找到一种算法来生成所有可能的 n 维 k,k,...,k 数组,每个数组都沿轴有一行 1。因此,该函数接受两个数字 - n 和 k,并且应该返回一个数组列表,其中包含沿
我们有 N 对。每对包含两个数字。我们必须找到最大数 K,这样如果我们从给定的 N 对中取 J (1 2,如果我们选择三对 (1,2),我们只有两个不同的数字,即 1 和 2。 从一个开始检查每个可能
鉴于以下问题,我不能完全确定我当前的解决方案: 问题: 给定一个包含 n 元素的最大堆,它存储在数组 A 中,是否可以打印所有最大的 K 元素在 O(K*log(K)) 中? 我的回答: 是的,是的,
我明白了: val vector: RDD[(String, Array[String])] = [("a", {v1,v2,..}),("b", {u1,u2,..})] 想转换成: RDD[(St
我有 X 个正数,索引为 x_i。每个 x_i 需要进入 K 组之一(其中 K 是预先确定的)。令 S_j 为 K_j 中所有 x_i 的总和。我需要分配所有 x_i 以使所有 S_j 的方差最小化。
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在研究寻找原始数的算法,看到下面的语句,我不明白为什么。 while (k*k <= n) 优于 while (k <= Math.sqrt(n)) 是因为函数调用吗?该调用函数使用更多资源。 更
我想找到一种尽可能快的方法来将两个小 bool 矩阵相乘,其中小意味着 8x8、9x9 ... 16x16。这个例程会被大量使用,所以需要非常高效,所以请不要建议直截了当的解决方案应该足够快。 对于
有没有一种惯用的方法来获取 Set和 Function ,并获得 Map实时取景? (即 Map 由 Set 和 Function 组合支持,例如,如果将元素添加到 Set ,则相应的条目也存在于 M
这个问题在这里已经有了答案: Can a local variable's memory be accessed outside its scope? (20 个答案) returning addr
给定一个矩阵:- k = [1 2 3 ; 4 5 6 ; 7 8 NaN]; 如果我想用 0 替换一个数字,比如 2,我可以使用这个:k(k==2) =
我是一名优秀的程序员,十分优秀!