oak.nfc
Class TagWriter

java.lang.Object
  extended by oak.nfc.TagWriter

public class TagWriter
extends Object

Created with IntelliJ IDEA. User: ericrichardson Date: 11/8/12 Time: 1:25 PM To change this template use File | Settings | File Templates.


Constructor Summary
TagWriter(android.content.Context context, String mimeType, android.app.Activity activity, android.app.PendingIntent pendingIntent, android.content.IntentFilter[] intentFilters)
          The constructor for a write tag object
 
Method Summary
 void clearPushMessage()
          A method to turn clear out the previous message to be pushed.
 void createMimeType(String name)
          a method to create a MimeType that the application will use when writing to a tag so that it knows which application / activity to bring up when the tag is touched.
 void disableNdefExchangeMode()
          Call to disable any sort of exchange between NDEF devices.
 void disableTagWriteMode()
          Disables the tag writing mode so that there is no confusion for the application as to whether it's about to write to a tag or not.
 void enableNdefExchangeMode()
          Call to enable an exchange between NDEF devices during the activity with the message to be written.
 void enableTagWriteMode()
          Enables the tag writing mode so that the application knows that it is ready to write something to a tag.
 byte[] getBytePayload()
          Gets the payload for a message from the array of NDEFmessages and then sets mPayload to that value and returns it.
 android.nfc.Tag getDetectedTag(android.content.Intent intent)
          a getter for a detected tag from an intent.
 android.nfc.NdefMessage getMessageFromArray()
          Gets the first message in the array of messages and sets the current message field to that value.
 android.nfc.NdefMessage getNdefMessage()
          A getter for the current NdefMessage.
 android.nfc.NdefMessage[] getNdefMessages()
          A getter for the NdefMessages array.
 android.nfc.NdefMessage[] getNdefMessages(android.content.Intent intent)
          Gets the NdefMessage array from a tag when it's discovered or from an NDEF device.
 String getPayloadString()
          A helper method to get the string version of whatever the current ndef message is.
 android.nfc.NdefMessage getTextViewAsNdef(android.widget.TextView view)
          Gets the message from a text view and turns it into an NDEF Message and returns it as well as setting the message field.
 boolean isNdefDiscovered(android.content.Intent intent)
          A method that determines if there's an NDEF action discovered from an intent.
 boolean isTagDiscovered(android.content.Intent intent)
          A method that determines if there's an NFC tag discovered from an intent.
 boolean isWriteMode()
          A getter for the boolean writeMode.
 void setMessage(byte[] bytes)
          A method to create an NDEF message from a byte array and sets the current message field to that value.
 void setMessage(String str)
          A method that will create an NDEF message from a string and set the current message to that value.
 void setPayloadString()
          a helper method to set a string from the payload of a single message.
 boolean writeToTag(android.nfc.NdefMessage aMessage, android.nfc.Tag tag)
          A big method that writes an NDEF message to a tag or displays a toast message as to why it failed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TagWriter

public TagWriter(android.content.Context context,
                 String mimeType,
                 android.app.Activity activity,
                 android.app.PendingIntent pendingIntent,
                 android.content.IntentFilter[] intentFilters)
The constructor for a write tag object

Parameters:
context - the context needed to create the NfcAdapter. (The activity)
mimeType - the mimetype for the application
activity - the activity that will be using this object
pendingIntent - the pending intent that handles all nfc intents
intentFilters - the filters needed for writing to a tag
Method Detail

enableNdefExchangeMode

public void enableNdefExchangeMode()
Call to enable an exchange between NDEF devices during the activity with the message to be written. Gives priority to the foreground activity when dispatching a discovered tag to an application. If this needs to be changed in the future, change what the message is, or list a different activity in setNdefPushMessage.


disableNdefExchangeMode

public void disableNdefExchangeMode()
Call to disable any sort of exchange between NDEF devices.


getTextViewAsNdef

public android.nfc.NdefMessage getTextViewAsNdef(android.widget.TextView view)
Gets the message from a text view and turns it into an NDEF Message and returns it as well as setting the message field.

Parameters:
view - The textView that contains the text to be turned into a message.
Returns:
Returns a new NdefMessage from the text.

setPayloadString

public void setPayloadString()
a helper method to set a string from the payload of a single message.


getPayloadString

public String getPayloadString()
A helper method to get the string version of whatever the current ndef message is.

Returns:
payloadString the string version of the payload of message if it has been set.

clearPushMessage

public void clearPushMessage()
A method to turn clear out the previous message to be pushed. This allows the NFC device to listen for incoming ndef messages.


getBytePayload

public byte[] getBytePayload()
Gets the payload for a message from the array of NDEFmessages and then sets mPayload to that value and returns it.

Returns:
mPayload the payload for the ndefMessage in the first position in the messages array.

getNdefMessage

public android.nfc.NdefMessage getNdefMessage()
A getter for the current NdefMessage.

Returns:
message the current NdefMessage.

getNdefMessages

public android.nfc.NdefMessage[] getNdefMessages()
A getter for the NdefMessages array.

Returns:
Returns messages which is an array of NdefMessages.

getMessageFromArray

public android.nfc.NdefMessage getMessageFromArray()
Gets the first message in the array of messages and sets the current message field to that value.

Returns:
message the current message stored in the WriteTag object.

getNdefMessages

public android.nfc.NdefMessage[] getNdefMessages(android.content.Intent intent)
Gets the NdefMessage array from a tag when it's discovered or from an NDEF device. Then it sets the field messages to that array.

Parameters:
intent - The intent that contains the action that is hopefully either ACTION_TAG_DISCOVERED or ACTION_NDEF_DISCOVERED
Returns:
messages Returns the messages array.

getDetectedTag

public android.nfc.Tag getDetectedTag(android.content.Intent intent)
a getter for a detected tag from an intent.

Parameters:
intent - the intent that contains the tag
Returns:
the Tag that is in the intent.

isWriteMode

public boolean isWriteMode()
A getter for the boolean writeMode.

Returns:
writeMode returns the boolean value that determines if it is currently in writeMode according to the boolean.

isNdefDiscovered

public boolean isNdefDiscovered(android.content.Intent intent)
A method that determines if there's an NDEF action discovered from an intent.

Parameters:
intent - the intent that might contain the NDEF Action.
Returns:
true if there exists an NDEF action in the intent.

isTagDiscovered

public boolean isTagDiscovered(android.content.Intent intent)
A method that determines if there's an NFC tag discovered from an intent.

Parameters:
intent - the intent that might contain a Tag Discovered action
Returns:
true if the intent contains a Tag Discovered action.

enableTagWriteMode

public void enableTagWriteMode()
Enables the tag writing mode so that the application knows that it is ready to write something to a tag.


disableTagWriteMode

public void disableTagWriteMode()
Disables the tag writing mode so that there is no confusion for the application as to whether it's about to write to a tag or not.


createMimeType

public void createMimeType(String name)
a method to create a MimeType that the application will use when writing to a tag so that it knows which application / activity to bring up when the tag is touched.

Parameters:
name - the name of the application that will be tacked on to the mimeType.

setMessage

public void setMessage(String str)
A method that will create an NDEF message from a string and set the current message to that value.

Parameters:
str - The String that will be used to create an NDEF message.

setMessage

public void setMessage(byte[] bytes)
A method to create an NDEF message from a byte array and sets the current message field to that value.

Parameters:
bytes - the byte array that will be used to create the NDEF message.

writeToTag

public boolean writeToTag(android.nfc.NdefMessage aMessage,
                          android.nfc.Tag tag)
A big method that writes an NDEF message to a tag or displays a toast message as to why it failed.

Parameters:
aMessage - the message to be written to the tag.
tag - the tag that the message is being written to.
Returns:
True if it succeeded in writing the message to the tag. False otherwise.


Copyright © 2011-2014. All Rights Reserved.