Search in sources :

Example 1 with NDEFMessage

use of net.rim.device.api.io.nfc.ndef.NDEFMessage in project Samples-for-Java by blackberry.

the class NfcSnepResponderMsgBuilder method buildNDEFMessages.

public NDEFMessage[] buildNDEFMessages() {
    Utilities.log("XXXX NfcSnepResponder Received Push Request");
    _screen.logEvent("rcvd:Received Push Request");
    NDEFMessage[] listOfNdefMessages = null;
    NDEFMessage myNdefMessage;
    try {
        Utilities.log("XXXX NfcSnepResponder Constructing Media Type: " + Constants.VCARD_MIME_TYPE);
        _screen.logEvent("send:Constructing Media Type: " + Constants.VCARD_MIME_TYPE);
        Utilities.log("XXXX NfcSnepResponder Constructing vCard Media Type NDEF Message: " + Constants.VCARD_DATA);
        _screen.logEvent("send:Constructing vCard Media Type NDEF Message: " + Constants.VCARD_DATA);
        myNdefMessage = NDEFMessageUtils.createMediaTypeNDEFMessage(Constants.VCARD_MIME_TYPE, Constants.VCARD_DATA.getBytes("US-ASCII"));
        listOfNdefMessages = new NDEFMessage[] { myNdefMessage };
    } catch (NFCException e) {
        e.printStackTrace();
        Utilities.log("XXXX NfcSnepResponder Exception on creating NDEF Message: " + e.getMessage());
        _screen.logEvent("warn:Failed to create NDEFMessage");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        Utilities.log("XXXX NfcSnepResponder Exception on conversion of vCard data: " + e.getMessage());
        _screen.logEvent("warn:Exception on conversion of vCard data");
    }
    return listOfNdefMessages;
}
Also used : NFCException(net.rim.device.api.io.nfc.NFCException) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with NDEFMessage

use of net.rim.device.api.io.nfc.ndef.NDEFMessage in project Samples-for-Java by blackberry.

the class NfcWriteNdefSmartTagListener method writeSpTag.

private void writeSpTag(String target_uri) {
    Utilities.log("XXXX Writing SP tag");
    NDEFTagConnection tagConnection = null;
    String willWriteMsg = "Writing Smart Poster Tag " + _screen.getTagDetails() + ",Language: " + URL_TEXT_LOCALE;
    _screen.logEvent(willWriteMsg);
    try {
        NDEFMessage smartPosterTag = createSmartPosterTag();
        tagConnection = (NDEFTagConnection) Connector.open(target_uri);
        tagConnection.write(smartPosterTag);
        Utilities.log("XXXX NfcWriteNdefSmartTagListener SP Tag written successfully");
        _screen.logEvent("SP tag written successfully");
    } catch (NFCException e) {
        e.printStackTrace();
        Utilities.log("XXXX NfcWriteNdefSmartTagListener NFCException");
    } catch (IOException e) {
        e.printStackTrace();
        Utilities.log("XXXX NfcWriteNdefSmartTagListener IOException");
    }
}
Also used : NDEFTagConnection(net.rim.device.api.io.nfc.ndef.NDEFTagConnection) NFCException(net.rim.device.api.io.nfc.NFCException) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) IOException(java.io.IOException)

Example 3 with NDEFMessage

use of net.rim.device.api.io.nfc.ndef.NDEFMessage in project Samples-for-Java by blackberry.

the class NfcWriteNdefSmartTagListener method writeCustomTag.

private void writeCustomTag(String target_uri) {
    Utilities.log("XXXX Writing Custom tag");
    NDEFTagConnection tagConnection = null;
    String content = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_CONTENT);
    String domain = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_DOMAIN);
    String type = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_TYPE);
    Utilities.log("XXXX domain:" + domain);
    Utilities.log("XXXX type:" + type);
    Utilities.log("XXXX content:" + content);
    try {
        NDEFMessage externalNdefMessage = NDEFMessageUtils.createExternalTypeMessage(domain, type, content.getBytes("US-ASCII"));
        tagConnection = (NDEFTagConnection) Connector.open(target_uri);
        tagConnection.write(externalNdefMessage);
        Utilities.log("XXXX NfcWriteNdefSmartTagListener Custom Tag written successfully");
        _screen.logEvent("Custom Tag written successfully");
    } catch (Exception e) {
        _screen.logEvent(e.getClass().getName() + ":" + e.getMessage());
        Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
    }
}
Also used : NDEFTagConnection(net.rim.device.api.io.nfc.ndef.NDEFTagConnection) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) IOException(java.io.IOException) NFCException(net.rim.device.api.io.nfc.NFCException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with NDEFMessage

use of net.rim.device.api.io.nfc.ndef.NDEFMessage in project Samples-for-Java by blackberry.

the class NfcWriteNdefSmartTagListener method writeTextTag.

private void writeTextTag(String target_uri) {
    Utilities.log("XXXX Writing Text tag");
    NDEFTagConnection tagConnection = null;
    String text = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_TEXT);
    try {
        NDEFMessage externalNdefMessage = NDEFMessageUtils.createTextNDEFMessage(text, URL_TEXT_LOCALE);
        tagConnection = (NDEFTagConnection) Connector.open(target_uri);
        tagConnection.write(externalNdefMessage);
        Utilities.log("XXXX NfcWriteNdefSmartTagListener Text Tag written successfully");
        _screen.logEvent("Custom Tag written successfully");
    } catch (Exception e) {
        _screen.logEvent(e.getClass().getName() + ":" + e.getMessage());
        Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
    }
}
Also used : NDEFTagConnection(net.rim.device.api.io.nfc.ndef.NDEFTagConnection) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) IOException(java.io.IOException) NFCException(net.rim.device.api.io.nfc.NFCException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with NDEFMessage

use of net.rim.device.api.io.nfc.ndef.NDEFMessage in project Samples-for-Java by blackberry.

the class NfcWriteNdefSmartTagListener method writeUriTag.

private void writeUriTag(String target_uri) {
    Utilities.log("XXXX Writing URI tag");
    NDEFTagConnection tagConnection = null;
    String uri = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_URI);
    try {
        NDEFMessage uriNdefMessage = NDEFMessageUtils.createUriNDEFMessage(uri);
        tagConnection = (NDEFTagConnection) Connector.open(target_uri);
        tagConnection.write(uriNdefMessage);
        Utilities.log("XXXX NfcWriteNdefSmartTagListener URI Tag written successfully");
        _screen.logEvent("Custom Tag written successfully");
    } catch (Exception e) {
        _screen.logEvent(e.getClass().getName() + ":" + e.getMessage());
        Utilities.log("XXXX " + e.getClass().getName() + ":" + e.getMessage());
    }
}
Also used : NDEFTagConnection(net.rim.device.api.io.nfc.ndef.NDEFTagConnection) NDEFMessage(net.rim.device.api.io.nfc.ndef.NDEFMessage) IOException(java.io.IOException) NFCException(net.rim.device.api.io.nfc.NFCException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

NDEFMessage (net.rim.device.api.io.nfc.ndef.NDEFMessage)8 NFCException (net.rim.device.api.io.nfc.NFCException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 IOException (java.io.IOException)4 NDEFTagConnection (net.rim.device.api.io.nfc.ndef.NDEFTagConnection)4 NDEFRecord (net.rim.device.api.io.nfc.ndef.NDEFRecord)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BadFormatException (net.rim.device.api.io.nfc.ndef.BadFormatException)1