Starting a web request when an nfc sticker is detected

1.8k Views Asked by At

Is there an app which calls a definable URL when a NFC sticker is detected? I want to put different stickers on my desk and when I place my phone on one of the stickers a specific URL should be call:

If StickerA is detectd call https://www.myserver.com/?val=a

If StickerB is detectd call https://www.myserver.com/?val=b

If StickerC is detectd call https://www.myserver.com/?val=c

etc.

Is this possible with android without activating the phone and is there a an existing app for that task?

4

There are 4 best solutions below

0
On

With Web NFC on Android, any website can write a URL NDEF Record to an NFC tag. This URL will be launched in user's browser on Android when user taps NFC tag.

const urlRecord = {
  recordType: "url",
  data:"https://w3c.github.io/web-nfc/"
};

const ndef = new NDEFReader();
await ndef.write({ records: [urlRecord] });

See https://web.dev/nfc/#read-and-write-a-url-record

0
On

you can write unique URL in every "sticker" or nfc tag by many Android App you can try NFC tools, then when you touch your Android device it will open the URL.

without activiating the Android device you will not be able to communicate with NFC tag*.

*you could with rooted device and you need to write the app by your self.

2
On

The Android OS itself has the ability to detect NFC and launch a web browser to open a URL on the NFC stickers/Tags (as long has the phone has NFC hardware and it is turned on)

The Sticker/Tag has to have the correctly formatted NDEF data written to it.

You can use https://play.google.com/store/apps/details?id=com.wakdev.wdnfc or other apps to write the correct data to the stickers/tags to store the URL correctly.

You can write your own App to do this as well but it does not require a "rooted device". But it does require then device to have the hardware and for it to be turned on.

0
On

Detecting a sticker, and taking an action are two different things. When you detect a sticker, I think you can get the ID of the sticker, then, based on the ID, you would create an Action View Intent passing the URL and that would cause an external browser window to open with the URL you passed.

//pass any url to this function to open a new browser session 
protected void handleExternalDeviceActivity(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
}