semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
119 stars 119 forks source link

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

Open VincentBayliss opened 3 years ago

VincentBayliss commented 3 years ago

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.

subinsv commented 3 years ago

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;