NDefContent
com.rvi.domain.NDefContent · Sealed interface · SocialCard 1.0.3
Common type for URI, text, contact and Wi-Fi records.
When to use it
Section titled “When to use it”Use List<NDefContent> to hold mixed records in tag order. Decode a message through readContents() or NDefDecoder.decode() and use a Java pattern switch to handle each record type.
Java example
Section titled “Java example”final NDefMessage message = new NDefMessageCreator() .add(new NDefUri("https://rithush.dev")) .add(new NDefText("My portfolio", "en")) .build();
for (final NDefContent content : new NDefDecoder().decode(message)) { final String label = switch (content) { case NDefUri link -> link.uri(); case NDefText text -> text.text(); case NDefContact contact -> contact.firstName() + " " + contact.lastName(); case NDefWifi wifi -> wifi.ssid(); }; System.out.println(label);}Java imports
import com.rvi.application.NDefDecoder;import com.rvi.application.creator.NDefMessageCreator;import com.rvi.domain.NDefContact;import com.rvi.domain.NDefContent;import com.rvi.domain.NDefMessage;import com.rvi.domain.NDefText;import com.rvi.domain.NDefUri;import com.rvi.domain.NDefWifi;The Wi-Fi branch shows the network name without exposing credentials.
How it works
Section titled “How it works”The sealed interface permits four records. NDefEncoder selects a payload format from the concrete type. A pattern switch over those four types is exhaustive, which lets the Java compiler check that every supported value has a handler.
Related API
Section titled “Related API”NDefUri · NDefText · NDefContact · NDefWifi · NDefDecoder