Search code examples
androidurinfcmime-typesndef

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?


Solution

  • 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 [email protected]), the URI would be

    mailto:[email protected]
    

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

    NdefRecord mailtoUri = NdefRecord.createUri("mailto:[email protected]");
    

    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:[email protected]?subject=mysubject&body=mytext");
    

    will create an NDEF record for a ready-made e-mail message to [email protected] with the subject "mysubject" and the message body "mytext".