Skip to content

NdefMessage

Daneo van Overloop edited this page Jun 17, 2014 · 2 revisions

Android NFC Library

Home Reading NFC Tags Writing NFC Tags Creating NdefMessages Exception Handling
How it works Reading Writing NdefMessages Exceptions

NdefMessage

This class is used to create the NdefMessages and provides several handy methods. You can create an instance of this class, call a method e.g. createEmail(), pass on the parameters, and be sure the returned NdefMessage is formatted with the correct Type Name Field and Record Type Definition.

This functionality is seperated due to these messages being used by either an Nfc Write operation, or Android Beam.

    /**
     * @param urlAddress
     *         The url, auto-prefixed with the http://www. header
     * @return true if successful
     */
    NdefMessage createUri(@NotNull String urlAddress) throws FormatException;

    /**
     * Creates a telephone number - NdefMessage
     *
     * @param telephone
     *         number to create
     * @return true if success
     */
    NdefMessage createTel(@NotNull String telephone) throws FormatException;

    /**
     * Create SMS - NdefMessage. Due to a bug in Android this is not correctly implemented by the OS.
     *
     * @param message
     *         to send to the person
     * @param number
     *         of the recipient
     * @return true if success
     */
    NdefMessage createSms(@NotNull String number, String message) throws FormatException;

    /**
     * Creates a Geolocation - NdefMessage.
     * @param latitude
     *         maximum 6 decimals
     * @param longitude
     *         maximum 6 DECIMALS
     * @return true if success
     */
    NdefMessage createGeolocation(Double latitude, Double longitude) throws FormatException;

    /**
     * Create recipient, subject and message email - NdefMessage
     *
     * @param recipient
     *         to whom the mail should be sent
     * @param subject
     *         of the email
     * @param message
     *         body of the email
     * @return true if success
     */
    NdefMessage createEmail(@NotNull String recipient, String subject, String message) throws FormatException;

    /**
     * Create the bluetooth address - NdefMessage
     *
     * @param macAddress
     *         to create NdefMessage. Must be in format XX:XX:XX:XX:XX:XX, separator may differ
     * @return true if success
     */
    NdefMessage createBluetoothAddress(@NotNull String macAddress) throws InsufficientCapacityException, FormatException, ReadOnlyTagException;


    /**
     * Create the message with plain text
     * @param text to transfer
     * @return prepared NdefMessage
     * @throws FormatException
     */
    NdefMessage createText(@NotNull String text) throws FormatException;

    /**
     * Create the address with the given header
     * @see #createUri(String)
     */
    NdefMessage createUri(String urlAddress, byte payloadHeader) throws FormatException;

Should you encounter a discrepancy between the standards from the NFC Forum and our implementation, be sure to inform us!

Clone this wiki locally