Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 08:17, 23 July 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Simple NFC PushRegistry example

From Wiki
Jump to: navigation, search
Article Metadata
Created: samuuh (14 Jun 2007)
Last edited: hamishwillee (23 Jul 2013)

Simple Java code example of using PushRegistry in NFC devices.

import javax.microedition.contactless.DiscoveryManager;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
// Simple Java code example of using PushRegistry to launch midlet.
public class PushRegistrySimpleExample extends MIDlet {
private Form form;
private TextField pushTextField;
private TextField launchTextField;
private DiscoveryManager dm;
protected void startApp() throws MIDletStateChangeException {
// Create UI
form = new Form("Form");
pushTextField = new TextField("Pushregistration", "", 255,
launchTextField = new TextField("Launch type", "", 255,
try {
// Make list of connections that are already registered
String[] regConns = PushRegistry.listConnections(false);
// Boolean to tell if wanted TargetType is already registered
boolean registered = false;
// Go trough list to see if wanted TargetType is already registered
for (int i = 0; i < regConns.length; i++) {
if (regConns[i]
.equals("ndef:external_rtd?")) {
registered = true;
// If TargetType is not registered - register it
if (!registered) {
// Register this MIDlet to be launched when any tag with right
// TargetType is touched
} else {
// If target was already registered write that on screen
pushTextField.setString("Connection already registered");
} catch (Exception e) {
// In case of exception write message on screen
pushTextField.setString("Exception: " + e.getMessage());
// Get instance of NFC Discovery Manager
dm = DiscoveryManager.getInstance();
// Show how MIDlet was launched: By touching tag or trough
// phones menu (touch/manual).
String launchType = dm.getProperty("LaunchType");
protected void pauseApp() {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
This page was last modified on 23 July 2013, at 08:17.
49 page views in the last 30 days.