Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AAR Record in NFC: Where's The Payload?

According to this answer, and validated by testing, when you use Android Beam to push over an NFC message containing an AAR record, the receiving device will start the MAIN/LAUNCHER activity for the app specified in the AAR.

That MAIN/LAUNCHER Intent does not contain the NfcAdapter.EXTRA_NDEF_MESSAGES extra. Hence, the data that we went through all the trouble to beam over appears to be lost if you use AAR.

Is there some way to get the NFC messages that triggered the app to be started in this scenario?

And if the answer is "no", then what is the use case of AAR? I can see where it might be helpful when the desired app does not exist on the receiving device (brings up Play Store), but then once the app is installed, AAR foils any attempt to deliver data from one device to the other, which is kinda the point behind NFC.

Thanks!

like image 705
CommonsWare Avatar asked Jun 04 '12 19:06

CommonsWare


People also ask

What is a record NFC?

Overview. A Website Record is an NDEF record used to open a url in a web browser on the device that is touching the NFC tag. Website records are the most common record type used. The urls of website records can contain unique parameters which the server can use to provide a dynamic response based on the parameter.

What kind of data is contained in NDEF?

An NDEF record contains a payload of data and metadata describing how to interpret the payload. Each record's payload can be one of several different data types. The header for each record contains metadata describing the record and its place in the message, followed by its type and ID.

What is NDEF text?

An NDEF text record is a record used to store plain (unformatted) text on an NFC tag.

What is NDEF tag?

NDEF is a standardized data format that makes it possible for a smartphone to write or read on an NFC card or an NFC tag. The NDEF format is used to store URLs, text documents, or electronic business cards. NFC-enabled chips such as the MiFare® NTAG® or DesFire® may be configured together with NDEF.


1 Answers

At the risk of answering my own question, one recipe for getting this to work (apparently) is:

  • Have the Beam sender use an NFC message with two NFC records, the first containing something for a unique MIME type, the second being the AAR

  • Have the Beam recipient have an <intent-filter> on the activity that responds to the first NFC record, such as via:

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    
            <category android:name="android.intent.category.DEFAULT"/>
    
            <data android:mimeType="application/vnd.commonsware.webbeam"/>
        </intent-filter>
    

If the app already exists, the NDEF_DISCOVERED Intent will be used, and the recipient can pick up the NFC message and pull out the data from the initial record. If the app does not exist, the AAR will kick in, bringing up the Play Store (whether your app is distributed through the Play Store or not).

This is the recipe shown in the Android Beam example on the developer site.

like image 84
CommonsWare Avatar answered Sep 22 '22 00:09

CommonsWare