android - 设置包名称是否会使隐式 Intent 显式化?

标签 android android-intent

如果没有第三行代码, Intent 将是隐式的。设置包是否使其明确?该组件未指定,因此基于 Stack Overflow answers :这是隐含的...

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage("com.example.app");
startActivity(intent);

...但是提供了目标应用程序的包名称,因此它是明确的,基于 docs :

Explicit intents specify which application will satisfy the intent, by supplying either the target app's package name or a fully-qualified component class name.

最佳答案

显式意味着定义的应用程序(也称为包)应该处理 Intent 。

当您设置应该处理 Intent 的包时,是的,它使它变得明确。

添加

我选择definition of explicit考虑在内,这意味着操作已定义。

fully and clearly expressed or demonstrated; leaving nothing merely implied; unequivocal:

然后如果检查setPackage docs它说

(Usually optional) Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.

因此,关键在于如何理解术语隐式显式

对我来说(根据我对 android 文档的理解),隐式是

Hey, I want to share this awesome image, lets give it to the world

这将打开 facebook、instagram、whatsapp 等的选择器。

显式的是

Hey, I want to share this awesome image with Instagram, open it and share the image please

仅打开 Instagram(按包)。

关于android - 设置包名称是否会使隐式 Intent 显式化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54538924/

相关文章:

android - RxJava Android 序列打印数据

android - 获取RecyclerView的选中项位置

java - 如何使用 jobscheduler 将 jobworkitem 排入队列

java - Android ProgressDialog 显示何时检索数据

java - 如何从以下 json 数组解析或创建 pojo?

android - 将数组列表从一个 Activity 传递到另一个 Activity

java - Android:无法启动 Activity :NullPointerException?

android - 谷歌浏览器无法在 Android 上的 Deep Link 上打开应用程序

android - jquery 拖放挂起或卡在 android 浏览器中

Android开发在VM中,但需要在本地设备上部署和调试