nfc_in_flutter icon indicating copy to clipboard operation
nfc_in_flutter copied to clipboard

QUESTION: How can I write a URL that launches the browser.

Open VincentBayliss opened this issue 5 years ago • 1 comments

Hi, when I write a URL/URI to a tag, the URL/URI is first opened in the default text editor. I can click on it and it will opens the browser but I would like just open the link in the browser when I scan that tag.

This can definitely be done. If I use say "NFC Tools" or the "NXP Tagwriter" app it launches the URL/URI in the browser (and not in the default text editor).

I'm sure its something I am doing but can somebody please give some guidance on how to achieve this?

Cheers and thanks in advance, Vincent.

VincentBayliss avatar Nov 06 '20 21:11 VincentBayliss

You can use NDEFRecord.uri(uri). This will launch the URL in browser

       NDEFMessage newMessage = NDEFMessage.withRecords([
          NDEFRecord.uri(Uri.parse(url_to_launch)),
        ]);

        NDEFTag tag = await NFC
            .writeNDEF(
              newMessage,
              once: true,
            )
            .first;

subinsv avatar Jan 18 '21 13:01 subinsv