What is the correct MIME type for mail and phone numbers?

I am currently working on NFC Android with NdefRecords on NFC tags. To store a business card (VCard), using this MIME type was enough:

text/vcard

But what is the MIME type for e-mail addresses or phone numbers?

Alternatively, can you suggest a good solution to write phone numbers and e-mail addresses onto NFC tags?

Answers


The proper way for storing telephone numbers (to make a call) and e-mail links (without passing a whole business card) would be to use URI records.

For a telephone call (for the number +431234567), the URI would be

tel:+431234567

On Android you can create an NDEF record containing that URI using

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

Or for sending an SMS:

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

For an e-mail (to myname@example.com), the URI would be

mailto:myname@example.com

On Android you can create an NDEF record containing that URI using

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

Btw. besides a simple recipient address, the mailto: URI scheme (as well as the sms:URI scheme) supports additional parameters like subject to specify a message subject and body to specify a message text (see the relevant RFCs for a full description of those capabilities, but note that Android does not support all of them). For example

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

will create an NDEF record for a ready-made e-mail message to myname@example.com with the subject "mysubject" and the message body "mytext".


This is my code I use to send emails with text and multiple attachments:

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);
}

With NFC you can use the mime type vcard. We have used e.g. "text/x-vCard" and it works fine, even including a photo.


Need Your Help

Numberformat seems to ignore decimal places in Android - but only for US-Dollar and only in Germany

java android string number-formatting

I'm having a really strange bug, where NumberFormat seemingly ignores the fraction digits I set.

What are the correct security policy value settings to allow both RMI and JPA/Hibernate to work at the same time

java jpa security-policy

I'm working on an application that requires the use of both JPA/Hibernate and RMI. Since RMI requires the use of a Security Policy to make sure that access to the network is correctly assigned I al...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.