Smart Poster VS plain text and URI - android

I am wondering what is the different between a smartPoster which has two records ( URI record , textRecord'json' ) and just two simple records first one is URI and the second is plain text'json'.
my second question is what the different between using MIME type and using plain text to send a json text form.

The answer to your first question is that the NFC Forum specifications allow for a Title on a the URI web link to be encoded. Therefore the smartposter specification contains both a a link and a text title and the URI spec contains only a link.
In practice, the title is almost completely redundant. All mobile phone readers will either launch the page or present the link. Additionally, it will take up memory space which will restrict your choice of NFC chip. In short, don't use the smartposter spec.
For your second question, it depends whether you refer to how the data is encoded on the tag or how the phone will interpret the data. I'll assume you mean how the phone will interpret which can be summarised as :
If you encode as text and you scan the tag from within an App then you can handle the data as you prefer. However, if the App isn't opened first, the phone will just think the data is text and (usually) display it as such.
If you encode as MIME type then, providing your App has already been installed on the phone and has registered the MIME type, then the phone will launch the App and pass the data. If you haven't installed the App, the phone will not know what to do.

Related

Workflow for using NTAG213 NFC to Identify Gym Members

What is the general workflow that I would develop to use wristbands equipped with NTAG213 NFC in order to authenticate gym members.
Currently in our database we have a "CardCode" field. In actuality it is named Barcode, but that is because the current method of authenticating is showing a barcode to a scanner that corresponds with a unique member.
Is the general workflow NTAG213 that I would "write" this member identifying information to the tag and then when that member tries to check-in it would attempt to read this field.
My previous experience with radio technology are RFID tags that would come pre-written from manufacturer with a site code and card code. Different vendors have different arrangements of the bits for site code, card code, and parity bits - so you have to know the bit format to read the tags and authenticate the member.
I get the feeling that the NTAG213 works more like a disk, I use a password from the MFG to be able to write to the NTAG213 and my readers use the information to authenticate. I suppose with this type of tech it would be unreasonable to have the MFG to pre-write something? I really don't know what the flow is.
For bonus, any example code with android.nfc would be awesome (I'm targeting Newland Nquire 304 (Android Kitkat 4.4)
Please advise.
A good place to start is the Tag's datasheet
At the low level the tag acts like a 2 dimensional array of memory 4 bytes wide and varying lengths.
As it is NFC Type 2 compliant you can use the NFC standard NDEF data encoding format and various OS's have methods to write NDEF encoded data without you having to worry about fitting the data correctly in to the 2 dimensional memory array.
Most cards come from the factory blank (but some vendors can add data to them for you with a cost).
While NTAG213 usually come from the factory with no password set on them, you have to set your own. The password can be set for write operations or both read and write operations.
The cards can also be made NDEF read-only but I would not recommend that, instead use the password.
How you use them depends on the level of security that is needed (to stop people cloning the cards to share one gym membership) and on if you want customers to read their own tags or if only certain hardware is required to read the tags that is tightly controlled.
Generally I would limit the hardware that can read/write to the tag, then you can set a password on read and write operations.
Then there would be 2 workflows.
New member
Get blank tag
configure the password for read and write
Authenticate with password
format the card for Ndef
Encode the data you want on the card using one or more Ndef records, at minimum, this should be your own Unique ID (Never use the Tag's UID as these are not Unique and can be cloned and are not protected by the password)
Gym checkin
Authenticate with password
Read the data from the Tag (At least the Unique ID you have written to the Tag)
I would recommend you use the ènableReaderMode Android API to tag detection, some code for that at https://stackoverflow.com/a/59397667/2373819
There are a lot of examples out there that use the older Android API enableForegroundDispatch but this is less reliable especially for writing data.
Overall you need to make sure decisions about what you want to store on the Tag and how you want to use it before you can decide how to write the code, otherwise the question is to big to answer in detail.

Read NFC tag without specific application?

I was wondering if there is any way to save a string of text (URL) to an NFC tag, let us say MIFARE or NTAG203, that can be read by other devices (smartphones) without the need of any special tag reading application.
I have tested several applications, e.g. Trigger for Android, and noticed that if the device reading the tag does not have the required application to read the data/instructions off the tag it still opens a URL that sends you to the Play Store to download that application.
So there must be a way to save some data readable by all/some NFC enabled phones. Simply put I want to create an applcation for Android that will write data to NFC tags and the data can be read/opened/executed by a random NFC enabled phone.
So is it possible to prepare an NFC tag that triggers some action on the reading device without requiring a specific application? What type of data could I write on an NFC tag with my app to achieve this?
First of all, in general, I agree with CommonsWare point of view that it's always a "special" app that handles NFC events. However, when looking into Android, I would consider the various platform apps from AOSP as part of the Android system. Even though not all of them may be available on all devices.
Looking into Andrid 4.4+, the following data types are handled by such system apps:
Browser: URIs with schemes "http:" and "https:".
Contacts and Dialer: MIME types "text/vcard" and "text/x-vcard" for importing contacts.
E-mail: URIs with scheme "mailto:"
In addition, if no other app handles a certain tag, NFC devices should(?) have the Tag app, that tries to handle various types (upon user confirmation):
URIs with scheme "tel" will cause an ACTION_CALL intent to call the given number.
URIs with schemes "sms"/"smsto" will cause an ACTION_SENDTO intent to start editing an SMS message.
Other URIs should(?) be forwarded in ACTION_VIEW intents.
MIME type records with type "text/x-vcard" (if not already handled) should be forwarded in ACTION_VIEW intents.
The text message of Text RTD records (not text/* MIME types!) should be displayed in the Tag app. Unfortunately many stupid(!) NFC apps register for Text records, thus you will normally not get to the Tag app.
MIME type records with type image/* (if image type is supported by Android) should be displayed in the Tag app.
Some records are handled by the NFC service itself (this should always be available on Android):
Android Application records (NFC Forum external type with type name "urn:nfc:ext:android.com:pkg") cause an ACTION_VIEW intent with the URI "market://details?id={PACKAGE_NAME}" to be sent.
NFC Forum external types with type name "urn:nfc:nokia.com:bt" are parsed for Bluetooth connection handover.
NDEF messages starting with a Handover Select RTD record and containing a MIME type record of type "application/vnd.bluetooth.ep.oob" are parsed for Bluetooth connection handover.
Everything with NFC involves an application for responding to the tag. Whether that is a "special tag reading application" depends on your own personal definition of "special tag reading application".
For example, some Web browsers will support NDEF-formatted tags with the payload being a URL. But that's a browser thing, not an OS thing. For example, the AOSP browser app has the manifest entry to respond to NDEF-formatted tags with URLs beginning with http or https. By my definition of "special tag reading application", the AOSP browser is a "special tag reading application". While hopefully all NFC-capable devices will ship with a Web browser that supports NDEF-formatted tags, that's not guaranteed.
If your "some data" is anything else, whether or not there is an app that is set up to respond to that sort of data. After URLs, the next-most-common tag payload is identified via a MIME type, just like you use with Web apps, and so if there is an app installed that supports NDEF and is set up to respond to your MIME type, it will pick up your data. This is no different than having your Web server serve up content under some MIME type -- an app needs to be installed that honors http/https URLs (or files downloaded by a browser) and that MIME type.
if the device reading the tag does not have the required application to read the data/instructions off the tag it still opens a URL that sends you to the Play Store to download that application
An AAR (Android Application Record) was added to the NDEF message written to the NDEF-formatted tag. That is the only NDEF item that can be thought of as being handled by the platform itself, and that's only for devices that support the Play Store (and apps that are distributed via the Play Store).

Two MIME type in NFC tag in Android

Can we add two MIME types in NFC tag while writing. I.e., I want to add two package names to MIME type. Actually I want to launch any one of the two application while reading the NFC tag from outside the app whichever application is installed.
You can write whatever information you want to a tag. MIME type records can contain any data (that fits the MIME type). You can also have multiple records on one tag.
Regarding your question of starting two different apps with one tag, you could simply use a URI record and have both apps contain an intent filter for that URI (so both apps share one URI). No need for different records here.

Share Wifi credentials via NFC tag without special apps

I am looking for a way to create a NFC-tag that shares the wifi credentials of my network without my guests having to have any special NFC apps on their phone (other than whats coming with the phone).
I have been looking at apps and services like NFC Tag Writer, WifiTap, NFC Task Launcher and NFCLabels.com, but it seems to me like it I would need to have the apps on the guest mobile as well to be able to use it, but I am not able to test it as I only have one NFC-enabled phone available. (Yes, I know, twisting my brains for nothing, but heck, weird behaviour is nothing new...)
My closest clue is that WifiTap states that:
The app processes URIs in the format of wifi://[network ssid]/[wep|wpa|open]/[network key]
If this is actually universal this would mean that I could do what I what I want to, but I have not found any confirmation on this. So, how could what I want be done and am I on the right track with the clue from WifiTap?
As Alex wrote in a comment, you can now (since Lollipop) write a tag containing Wi-Fi credentials directly from the Android Wi-Fi settings: long-tap a network → Write to NFC tag.
It seems to be an NDEF-formatted tag with the application/vnd.wfa.wsc MIME type and a "WPS NFC" token.
The relevant source code can be found in platform/packages/apps/Settings/src/com/android/settings/wifi/WriteWifiConfigToNfcDialog.java.
There is an official standard for this kind of situation: NFC Forum Connection Handover Technical Specification. However, this is currently not supported by Android. I don't think there is currently any way to transfer WiFi credentials using NFC without the help of a dedicated app.
One way of going about this is to create (or find) an app in the Google Play Store that has the following properties:
Intent filter for ACTION_NDEF_DISCOVERED and as URI the URL of the app in the Play Store.
Intent filter for ACTION_NDEF_DISCOVERED and as type some proprietary type (e.g. a MIME type)
Then you can create tags with an NDEF message containing the following NDEF records:
SmartPoster record with Play Store URI and some descriptive text (e.g. name of the app)
Record of proprietary type containing the WiFi credentials
Android Application Record for the app
The 3rd record will make sure that the proper app will always be started or the device user will be redirected to the Play Store to install it. This works only on ICS, however, but the 1st record (combined with the 1st intent filter) serves the same purpose on Gingerbread.
I've created an app which actually writes networks to tag in a standardized way - the problem is that Android does not currently recognize the handover records and automagically add them. And maybe that is all right - after all there is more to adding a network than just adding a network; you might for example verify the composer of the tag contents and so on.
Also, if you'd like to write more than one network to a tag, there might simply not be enough space to do it in the right (using standardized records) way.
I may have the wrong end of the stick but with the app nfc tools downloaded form the play store you can write a wifi network onto a tag that when scanned with defult android 5.0.2. On a nexus 7 2013 opens a message box asking confirmation formthe wifi connection, although this has always failed bar o
A URI of the form WIFI:T:WPA;S:SSID;P:PASSPHRASE;; will set WiFi if encoded to a QR code and scanned; but when encoded to an NFC tag it is unrecognized as a URI. This suggests to me that the NFC API is deficient in Android.

NFC Sticker/Tag Encoding

So here is my basic motivation for my question obfuscated a little:
I want to track a users loyalty to a particular store. Each store would have a NFC sticker on the register. On purchase the user would use an app on their phone (NFC available of course) and the sticker would send back some code that designates the store.
Now here is my question, one, can I send a simple code back to my application that is then, for example, added to some database? This link, near the bottom, provides a description of 'Content Options' none of which I want. Also, the NFC-Forum specifications don't tell me much (or I'm just not looking in the right place).
Also, how do I actually put this tag/code onto one of these stickers? If I do it myself can I make them read-only?
you can put arbitrary information on the NFC tag - there is no limitation what you can upload and in which format. Think about NFC tags like if they were normal data storage places like e.g. hardrive or CD - to those you can save to them files with arbitrarty format holding the arbitrary content. Same with NFC tags.
Anyway there is recommended NFC Forum standard for the content format called NDEF (NFC Forum Data Exchange Format is a lightweight binary message format designed to
encapsulate one or more application-defined payloads into a single message construct.)
Also for specific data (links, Phone number, calendar event, etc.) there is another recommended NFC Forum standard called RTD (Record Type Definition specifies the format and rules for building standard record types used by NFC Forum application definitions and third parties that are based on the NDEF data format).
So in fact you can use arbitrary data format or NDEF, for the data itself you can follow RTD recommendations or not... It is up to you.
For tag writing you can buy some existing software and USB NFC reader/writer or you can program your own software - this is more difficult, since you must know HW characteristic of tag you would like to use.
All tags allow permanent data locking.
Regards,
STeN
www.mautilus.com, petr.mazanec#mautilus.com
For Android devices, you would create a tag with an so-called Android Application Record (AAR). The AAR contains the package name of your application, and, using a technology called Beam, Android automatically launches your application. You are then free to access the other records contained within the NDEF message, which then probably would contain the id of the shop somehow, and contact your site.
I have tried AAR already and it works, also I have created an NFC Eclipse plugin which would get you up and running in no time, if you have an Android phone and some tag, of course ;-)

Categories

Resources