Search in sources :

Example 1 with NDEFTagConnection

use of net.rim.device.api.io.nfc.ndef.NDEFTagConnection 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 2 with NDEFTagConnection

use of net.rim.device.api.io.nfc.ndef.NDEFTagConnection 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 3 with NDEFTagConnection

use of net.rim.device.api.io.nfc.ndef.NDEFTagConnection 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 4 with NDEFTagConnection

use of net.rim.device.api.io.nfc.ndef.NDEFTagConnection 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

IOException (java.io.IOException)4 NFCException (net.rim.device.api.io.nfc.NFCException)4 NDEFMessage (net.rim.device.api.io.nfc.ndef.NDEFMessage)4 NDEFTagConnection (net.rim.device.api.io.nfc.ndef.NDEFTagConnection)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3