【问题标题】:What is the correct MIME type for mail and phone numbers?邮件和电话号码的正确 MIME 类型是什么?
【发布时间】:2014-10-01 13:49:55
【问题描述】:

我目前正在使用 NFC 标签上的 NdefRecords 开发 NFC Android。要存储名片 (VCard),使用这种 MIME 类型就足够了:

text/vcard

但是电子邮件地址或电话号码的 MIME 类型是什么?

或者,您能否提出一个将电话号码和电子邮件地址写入 NFC 标签的好的解决方案?

【问题讨论】:

  • text/plain 呢?
  • text/plain 仅适用于普通文本。如果我使用文本/普通 NFC 阅读器将其作为普通文本读取,则不应
  • 我使用*/* 发送电子邮件,因为我使用附件
  • 我认为我在制作唱片时犯了一个错误。能否请您显示形成电子邮件记录格式的代码?

标签: android uri nfc mime-types ndef


【解决方案1】:

存储电话号码(拨打电话)和电子邮件链接(不传递整个名片)的正确方法是使用 URI 记录。

对于电话(号码 +431234567),URI 为

tel:+431234567

在 Android 上,您可以使用以下方法创建包含该 URI 的 NDEF 记录

NdefRecord callUri = NdefRecord.createUri("tel:+431234567");

或发送短信:

NdefRecord callUri = NdefRecord.createUri("sms:+431234567?body=MyMessage");

对于电子邮件(发往 myname@example.com),URI 为

mailto:myname@example.com

在 Android 上,您可以使用以下方法创建包含该 URI 的 NDEF 记录

NdefRecord mailtoUri = NdefRecord.createUri("mailto:myname@example.com");

顺便说一句。除了简单的收件人地址之外,mailto: URI 方案(以及 sms:URI 方案)还支持其他参数,例如 subject 指定消息主题和 body 指定消息文本(请参阅相关 RFC这些功能的完整描述,但请注意 Android 并不支持所有这些功能)。例如

NdefRecord mailtoUri = NdefRecord.createUri("mailto:myname@example.com?subject=mysubject&body=mytext");

将为发送到 myname@example.com 的现成电子邮件创建一个 NDEF 记录,主题为“mysubject”,邮件正文为“mytext”。

【讨论】:

  • 是的,这工作正常。但是对于邮寄它的预填邮件部分,我还需要预填主题和正文部分。有什么建议吗?请等待您的回复。
  • 您是否尝试过使用mailto:myname@example.com?subject=something&body=mytext
  • 你能用你的评论更新你的答案吗?
【解决方案2】:

这是我用来发送带有文本和多个附件的电子邮件的代码:

private final void sendEmailWithMultipleAttachments
(
    final String[] to, final String[] cc, final String[] bcc,
    final String subject, final String body, final List<String> filePaths
) throws ActivityNotFoundException
{
    final Intent tnt =
        new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    ////tnt.setType("plain/text");
    //tnt.setType("text/plain");
    //tnt.setType("message/rfc822");
    //tnt.setType("text/xml");
    tnt.setType("*/*");
    tnt.putExtra(android.content.Intent.EXTRA_EMAIL, to);
    //tnt.putExtra(android.content.Intent.EXTRA_CC, cc);
    //tnt.putExtra(android.content.Intent.EXTRA_BCC, bcc);
    tnt.putExtra(Intent.EXTRA_SUBJECT, subject);
    //tnt.putExtra(Intent.EXTRA_TEXT, body);

    if (filePaths != null)
    {
        // It has to be an ArrayList
        final ArrayList<Uri> URIs = new ArrayList<Uri>();
        // Convert from paths to Android friendly Parcelable URIs
        for (final String file : filePaths)
        {
            final File fileIn = new File(file);
            if (fileIn.exists())
            {
                final Uri u = Uri.fromFile(fileIn);
                URIs.add(u);
            }
        }
        tnt.putParcelableArrayListExtra(Intent.EXTRA_STREAM, URIs);
    }

    // TEST ONLY:
    /*
    System.out.println("to     : " + to[0]);
    System.out.println("subject: " + subject);
    System.out.println("file/s : " + filePaths.size());
    */

    // It has to be "this"!!
    //this.startActivity(Intent.createChooser(tnt, ""));
    //this.startActivity(Intent.createChooser(tnt, "Choose an eMail Client"));
    /*
    // Without the "Use this actios as default" checkbox
    startActivity
    (
        Intent.createChooser
        (
            tnt, getString(R.string.choose)
        )
    );
    */
    // With the "Use this actios as default" checkbox
    startActivity(tnt);
}

【讨论】:

  • 我对 NFC/NDEF 没有任何线索
【解决方案3】:

通过 NFC,您可以使用 mime 类型的 vcard。我们使用了例如“text/x-vCard”,它可以正常工作,甚至包括照片。

【讨论】:

    猜你喜欢
    • 2011-01-13
    • 2017-12-19
    • 2016-02-19
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 2011-03-29
    相关资源
    最近更新 更多