I have an android device with this app installed on it. Then have a second device that I have factory-reset. Both are NFC enabled. And I am trying to provision the second device with a device owner application. I want to understand how this works. I am under the impression that when I bump the two devices together, something should happen. However, nothing happens. Both devices are on and I believe that I am bumping them in the right places. I have not worked with NFC before.
On the NFCProvisioning app provided by Google, that I linked above, I can see that the wifi ssid, and password are set in the ndef message. However, the url to the deviceowner app is not set anywhere. How will the device being provisioned know how to download the apk?
Also what about this nfcprovisioning.txt? Please, can someone who has done this before help me out. Many thanks!
So Now I have more time I can give a full answer.
So some background on Android and NFC first.
The Android OS has some built in parsing and handling of some types of data on NFC cards, it will handle cards with NDEF messages on them.
When an NFC card is presented the OS will attempt to read and understand the card. If there is no App running that has expressed and interest in NFC NDEF messages it will handle some types of NDEF messages in certain was.
E.g. If the NDEF message contains record with the Mime Type saying "Web Address" the OS will launch a web browser (or ask the user which web browser to open the URL in)
An NDEF message can also contain an "Android Application Reference" or AAR record, this specifies a package name that should handle the data on the card. If that application is not installed it will open up google play to install it.
(https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#aar)
Details on Mime Types and AAR at https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#create-records
This is all done by they OS creating an Intent from the NDEF data and passing it to applications.
So more specific to NFCProvisioning creates an NDEF message of a special Mime Type "application/com.android.managedprovisioning" that Android Understands is about Device Provisioning and that to use a package name that is was given or "com.example.android.deviceowner" or "com.example.android.deviceowner/.DeviceOwnerReceiver" if non given.
The package name could be one found on the play store but it also has a option to specify a URL to download the management app package from.
There is other data included in the NDEF message to Like Wifi details, time zone etc will will be passed on the the Device provisioning app.
Details of what can be passed is at https://developer.android.com/reference/android/app/admin/DevicePolicyManager#MIME_TYPE_PROVISIONING_NFC I believe
The problem you might be suffering is that the method used for the Provisioner device uses to send the data is NfcAdapter#setNdefPushMessage http://developer.android.com/reference/android/nfc/NfcAdapter.html#setNdefPushMessage(android.nfc.NdefMessage,%20android.app.Activity,%20android.app.Activity...) which has been deprecated in API level 29/ Android 10 (and no longer works)
see the issues raised on this https://github.com/android/enterprise-samples/issues/27
I have not used this process before, but looking at the code the "nfcprovisioning.txt" is just a text file you can load in that stores the values of the key=value pairs instead of having to type them in to the App every time.
e.g. it would have lines like for that the data you want to provision
EXTRA_PROVISIONING_WIFI_SSID=someWifiSSid
Related
First of all, apologies for the lack of code within this question. It's purely for information to further develop my project.
I'm after using nfc tag technology with mobile phones, what I want to achieve is on scanning of an nfc tag, my local or cloud server is updated with the ID and time/date of scan.
I've looked on various forums, done countless searches on the web but for some reason cannot find a clear point to start from.
I'm comfortable with all web languages however I just can't get my head around the process, do you scan a given nfc tag which then loads a url with the ID of the tag in a get method.
Or is there something I can do within an app which will update the server on scan.
Again apologies.
A simple way is to store a URL in the NFC tag which points to your server application. You can add an ID to the URL, which identifies the tag towards the server. The timestamp can come from the server, when he receives the HTTP Request. Your server application can then store the ID together with the time.
This approach will not need any specific app on the mobile, any NFC capable phone will do that out of the box.
Should you need a local timestamp from the mobile phone, then will need an NFC app which takes the NFC intent, formes the proper URL including the locally generated data and send that off to your server.
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).
I have an app that design personalized tags that, when it is detected by an android phone, launches another app with some content. It all works fine and I know how to make a read only nfc Tag. The problem is, I would like to make a NFC Tag only readable by users of the other app. But I also want , if necessary, modify these tags in order to be rewritten. But I want to prevent from users to do themselves.
that's why a ndef.makeReadOnly() is not appropriate for me..
does anyone can help me ???
It depends somewhat on the exact tags you will be using. The standard NFC Forum tag types for storing NDEF messages that Android supports have no specific functionality defined for this. So the Android API does not provide it either. There is only makeReadOnly(), which in most cases makes the tag irreversibly read-only.
However, when you look at the chips inside the tags that actually implement the required NFC functionality, they often provide more functions. These extra functions may include access control for writing, allowing the chip to be configured like you want.
Some examples (all manufactured by NXP, as I am most familiar with those):
MIFARE Classic: the memory sectors are protected by 2 keys. One key can be configured for read-only, while the other can be used to write the memory. NB: not all Android devices can access these!
MIFARE Ultralight C: can provide additional password protection to prevent overwriting
MIFARE DESFire: multiple authentication keys and access rights can be configured, including read-only access without keys
ICODE SLI(X)-S: can provide additional password protection to prevent overwriting
Most of these tags are generally available for sale on-line. You will have to hunt a bit on the internet to gather all the information on how the configuration has to be done, though. There is PC software available in most cases.
The only 100% way to make NFC tag "read only" is to call makeReadOnly(), but this is irreversible.
You can use "out of the box" solution, like:
do not write data on NFC tag but instead save it locally (if data is limited to one device) or to a server/cloud (if data si global)
link your NFC Tag ID (getByteArrayExtra(NfcAdapter.EXTRA_ID)) with your saved data
when NFC Tag is read get its ID and find proper data via proper source (local or cloud DB)
.. if second app is "third party app" and cannot work with upper soultion, you can register your own NFC reading app (intent with right mimeType filter) and then pass your data (point no. 3) to main app using sendIntent (or similar supported method).
Hope it helps!
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.
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 ;-)