Can you please help me write an app which on tapping an NFC sticker write data such as Name, Mobile and Email. Once user reads the NFC it should open the save to contacts option with all data pre-filled in.
I am using NDEF plain/text format. Am I headed in the right direction ?
Cheers,
Ishwar
There is no real need to write an app for that. When tapping an NFC tag with an NDEF message with the MIME type "text/vcard" and payload data formatted according to the vCard standard, the vCard data will automatically be imported into the contacts app.
Related
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.
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).
How would you beam a contact using your own app (and using Android Beam) to another device and have it saved in their contact list (i.e. the default contacts app). The contact on the sending device will be provided by the ContactsContract provider.
Preferably I don't want to have the other device running my app. The built-in contacts app (Android's default app) can beam and receive contacts. So it should be possible to beam a contact using a custom app to the built-in contacts app.
The answers to this question suggest that it's possible and that you can use the VCARD format.
Currently, my app will search for a contact by phone number, then display it in a new activity (which is the built-in contacts app). See below.
Uri uri = Uri.fromParts("tel", number.getText().toString(), "");
Log.d("ContactPicker", uri.toString());
startActivity(new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, uri));
// Example log message for the number (123)-123-1234 is "tel:(123)%20123-1234"
I'd prefer to do it this way, but don't think it's possible because I can't return the contact that was found (or the contact that was created if no existing one was found). And I need that information if I want to beam that specific contact.
I'll probably need to query all contacts, find the contact I'm looking for and save its ID.
Note: I'm using API 14
Edit
I made a proof of concept app that does this: https://github.com/dideler/HiFive
The app might be buggy. It's not maintained, but pull requests are welcome.
Yes, vCard is the way to go. It is the format that the built-in Contacts/People app will pick up. It is also the format that the app uses to store its own data, and I believe.
I've been able to successfully write URL and text data to RFID tags, these are recognized by the Android Tags app, but I have been unable to get the Tags app to recognize vcard data. Where I would assume it would give me the option to add contact after scanning I only see the MIME type text/x-vcard.
Can anyone confirm whether or not the Tags app will recognize vcard data?
Thanks,
Chris
Yes, the tags app should be able to recognize v-card data.
I've used the NXP TagWriter app to write a vcard to a Mifare Classic card, then read it in via the Tags app. It showed up as a contact type and allowed me to import the contact into the contacts system.
I've also had success in using the Tags app to read vcard data off of a demo NFC-enabled business card.
Did you try the recommended Android app from NXP? You can find the applications at google play: https://play.google.com/store/apps/developer?id=NXP+Semiconductors
The TagWriter app lets you write urls, contact, text or sms. If you do so with a brand new mifare tag the app will show a message before confirmation that the tag needs to be formatted for NDEF first.
This routine worked fine for me with a new tag. A Nexus 7 tablet showed the contact card when the tag was presented afterwards.
I also tried the same routine with a tag that was previously formatted as an NDEF tag but that failed. Each time I tried it turned up as an empty NDEF tag. I used the NFC TagInfo app (see link on top) for checking the contents of that tag and it turns out that only one sector (sector 1, counting from 0) is written with the vcard information. Resulting in an incomplete tag. Because the tag is already NFC formatted the tagWriter app doesn't propose to format the tag. My guess is that it's badly formatted, not to the full 1K size size.
Make sure to enable full scan at scan level using the preferences of the taginfo app.
I want to make VCard manager in android for 1.5 and above . This application will be able to perform following functions:
1 Send and receive contact . I want that when i send a contact to any mobile it should get the save option to save the contact and if some send me a business card then i should be able to save it in my contacts.
Can you please suggest me how to do it.
Is there any particular format for sending a VCard . For eg in nokia phones we are able to send a contact and its details(email etc) in form of business card and the other person can save it .
Can the same thing be achieved in android ?
Regards
Gaurav Gupta
# Keenora Fluffball
HI i am able to fetch the contacts details and able to send it in the format specified by you.. when i receive vcard in that format i want that i should get a save to contacts option. Though i can do this by using broad cast receiver. if a message contains text like BEGIN:VCARD
BEGIN:VCARD
VERSION:2.1
N:Gaurav;TEL;PREF9780898201
END:VCARD
But what about the other phones whether they will respond to it like in nokia we get popup business card received.
I want it to work on all phones. whether it is nokia or android.
Please suggest..