4

I don't have an NFC 'phone to try it out. A colleague absolutely insists that if you tap an NFC tag which stores a URL then that URL is launched automatically by the operating system.

That doesn't sound right to me and the developer docs says

Reading NDEF data from an NFC tag is handled with the tag dispatch system, which analyzes discovered NFC tags, appropriately categorizes the data, and starts an application that is interested in the categorized data. An application that wants to handle the scanned NFC tag can declare an intent filter and request to handle the data.

That sounds like what I expected (a BroadcastReceiver - or possibly a listener?). Can I tell him categorically that he is 100% wrong?

The reason being that he wants me to develop a small system for him and, while I see that I need a minimal Android app to listen for an NFC Tap event and then launch the browser, he insists that no app is needed and that any NFC enabled Android device, fresh from the factory, when tapping an NFC tag containing a URL will launch the browser to that URL.

  • 3
    I just tried one outside the office and it opened the "Open Link In" dialogue with Chrome/Internet/Dolphin as the options. The phone has been factory reset today. Beyond that I can't tell you how it should work, and what changes have been made to this in different versions of Android. I tried it on a Galaxy S4 GPE with Lollipop. UPDATE: Someone in the office tried it on a HTC M7 just there and it opened in the browser with no interaction, only one browser installed. – RossC Jan 21 '15 at 13:05
  • 1
    I cannot test because I don't have NFC tag which contains a URL, but based from RossC's comment, I guess Android receive it as normal URL, then handle it based on its URI scheme, just like when a user clicks URL on native app (not from browser itself). However, that's only my assumption. – Andrew T. Jan 21 '15 at 13:34
  • @RossC thanks. Can you post that as an answer, please? – Mawg Jan 22 '15 at 7:48
  • Please see my followup question android.stackexchange.com/questions/96564/… – Mawg Jan 22 '15 at 12:40
3

From trying it on two devices:

Galaxy S4 Google Play Edition: Lollipop 5.0, with multiple browsers. Once tagged the prompt to choose my browser comes up, and then once chosen opens the URL in the selected browser. The device was factory reset that morning.

HTC M7: Stock 4.4 up to date, no reset done, one browser. Opened straight in the browser.

3

'Next bus' NFC tags at bus stops here in London attempt to open in a browser - if you've just got one browser, fine, it'll automatically open in that... no need for permissions, logins or a special app. But like everything else on your phone if you've multiple choices for browser, reader, editor... etc., it'll open a 'complete action' dialogue - and continue this process - until you choose one as default.

2

The URL is launched using Android's intent system.

You can register a application for all URLs (like a web browser) or for only specific URLs. For example, you can register for http mybusticket.com/ticketid/* with your bus ticket application and Android will then ask the user which app the user wants to launch (if there are multiple that can handle that URL) when the NFC tag is scanned.

The Youtube app does this for example. NFC tags are handled mostly the same way.

https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#dispatching http://developer.android.com/guide/components/intents-filters.html#Receiving

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.