Skip to content

NDefContent

com.rvi.domain.NDefContent · Sealed interface · SocialCard 1.0.3

Common type for URI, text, contact and Wi-Fi records.

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.

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.

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.

NDefUri · NDefText · NDefContact · NDefWifi · NDefDecoder

Method signatures in the Javadoc · All API types