电子邮件意图的附加功能 - 首选项 XML

发布于 2024-11-28 09:04:23 字数 515 浏览 1 评论 0原文

我想从我的 xml 首选项屏幕触发电子邮件,并附加预定义的主题并在电子邮件应用程序的正文字段中启动光标

这是我到目前为止所得到的内容

  <Preference
    android:title="Support"
    android:summary="Having a problem?">

    <intent
      android:action="android.intent.action.VIEW"
      android:data="mailto:[email protected]"
      />

  </Preference>

非常适合触发电子邮件意图,但是我将如何通过 xml 完成其他任务?附加主题和所有内容?

I'm wanting to trigger an Email from my xml preferences screen and also attach a pre-defined subject and start the cursor in the Body field of the email application

Here's what I've got so far

  <Preference
    android:title="Support"
    android:summary="Having a problem?">

    <intent
      android:action="android.intent.action.VIEW"
      android:data="mailto:[email protected]"
      />

  </Preference>

Works great for triggering the email intent, but how would i go about accomplishing the others via xml? attaching the subject and all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必了 2024-12-05 09:04:23

正如 jondavidjohn 所说,您可以使用 mailto 查询参数,也可以使用意图附加参数,并且您可以混合和匹配它们。例如:

<intent
  android:action="android.intent.action.VIEW"
  android:data="mailto:[email protected]?subject=this is a test subject">
  <extra android:name="android.intent.extra.TEXT" android:value="This is a test" />
</intent>

...将允许您设置电子邮件的正文和主题。您还可以指定主题作为额外内容。这也让您可以使用 XML 字符串资源而不是硬编码:

  <extra android:name="android.intent.extra.SUBJECT" android:value="@string/email_subject" />

我刚刚从 Intent.java 中获取了 Intent 的额外名称;与电子邮件相关的都集中在一起。

我刚刚发现这一点,还没有进行太多测试,但这似乎确实适用于我的 GMail 邮件客户端。

另外,如果有任何帮助的话,我确实成功地使用了 mailto: URI 的“正文”,例如,

 mailto:[email protected]?subject=This%20is%20a%20subject&body=This%20is%20a%20body

不知道我对 mailto URL 进行 url 编码是否有帮助;我只是出于习惯的力量而这样做,来自网络背景。但这确实有效,并且在 GMail 和 K9 Mail 应用程序中都具有一定的作用。

You can use both mailto query parameters, as jondavidjohn says, and also intent extras, and you can mix and match them both. For example:

<intent
  android:action="android.intent.action.VIEW"
  android:data="mailto:[email protected]?subject=this is a test subject">
  <extra android:name="android.intent.extra.TEXT" android:value="This is a test" />
</intent>

...will allow you to set the body of an email as well as the subject. You can also specify the subject as an extra. This lets you use XML string resources rather than hardcoding, too:

  <extra android:name="android.intent.extra.SUBJECT" android:value="@string/email_subject" />

I just grabbed the Intent extra names from Intent.java; the email-related ones are all in a bunch together.

I've only just discovered this and haven't done much testing, but this certainly seems to work with my GMail mail client.

Also, if it's any help, I did have success using the "body" of the mailto: URI, e.g.

 mailto:[email protected]?subject=This%20is%20a%20subject&body=This%20is%20a%20body

Don't know whether it helped that I url-encoded my mailto URL; I was just doing it through force of habit, coming from a web background. But that definitely works and sets a body in both GMail and K9 Mail apps.

泪冰清 2024-12-05 09:04:23

显然,您可以使用普通浏览器 mailto: uri 上可以使用的许多查询字符串参数。

因此,要实现此目的,您只需像这样使用它们即可。

<intent
  android:action="android.intent.action.VIEW"
  android:data="mailto:[email protected]?subject=this is a test subject"
  />

Apparently you can use many of the querystring arguments that you can on the normal browser mailto: uri.

So to accomplish this you just have to use them like this.

<intent
  android:action="android.intent.action.VIEW"
  android:data="mailto:[email protected]?subject=this is a test subject"
  />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文