android - 为什么隐式电子邮件 Intent 可以在不指定 IntentFilter 的情况下工作?

标签 android android-intent

我使用隐式电子邮件 Intent 创建了一个电子邮件应用程序:

enter image description here

我知道我需要在 list 文件中添加 Filter 。它适用于这些过滤器。

<intent-filter>
    <action android:name="android.intent.action.SENDTO"></action>
    <data android:mimeType="*/*"></data>
    <data android:scheme="mailto" />
    <category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>

我的问题是,为什么在移除 intent-filter 后它仍然可以正常工作?。我无法理解为什么它在没有任何过滤器信息的情况下工作。 Android 文档说:

To pass this filter, the action specified in the Intent must match one of the actions listed in the filter. If the filter does not list any actions, there is nothing for an intent to match, so all intents fail the test. However, if an Intent does not specify an action, it passes the test as long as the filter contains at least one action

最佳答案

链接图片中的代码与此类似:

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.setData(Uri.parse("mailto:ejemplo@ejemplo.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "asunto de prueba");
intent.putExtra(Intent.EXTRA_TEXT, "probando el envio");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"suppport@ourcompany.com"});
startActivity(intent);

之所以有效,是因为 Intent.ACTION_SENDTO 是一种通用的“非显式” Intent ,Android 设备上的许多应用都支持该 Intent 。这些应用程序(例如 GMail)已经包含一个带有处理 android.intent.action.SENDTO 操作的 intent 过滤器的 Activity 。

如果您正在编写电子邮件应用或其他能够发送消息的应用,那么您的应用也应该考虑支持此 Intent 操作。

如果另一方面,您的目标只是让用户发送电子邮件,那么就没有必要了,因为 Android 设备上已经有很多应用程序可以发送电子邮件。此外,用户很可能更愿意为此类任务选择自己的电子邮件应用程序。

关于android - 为什么隐式电子邮件 Intent 可以在不指定 IntentFilter 的情况下工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54612512/

相关文章:

Android-当用户点击通知时打开浏览器

android - 将信息从 CustomDialog 传递到主 Activity

java - Intent.getStringExtra 上出现空指针异常。 : Android

android - 使用 Intent 的 Action 启动 Activity 并将其限制在 App 内

java - Android Intent 不开始新 Activity ?

android - React Native 获取调用在 iOS 中工作,但在 Android 中不工作

android - 当用户通过 Market Place 更新时,我的 Android 应用程序和数据库会发生什么情况?

java - 无法解析符号 SetOnEditorActionListener

android - 如何在较旧的 Android 版本上正确呈现 RTL 文本

javascript - 类似于 Android 调试的 Firebug