Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 18:16, 20 May 2008.

Detect secure element activity

From Forum Nokia Wiki

Simple MIDlet that notifies the user about secure element activity in card emulation mode.
package test;
 
import javax.microedition.contactless.DiscoveryManager;
import javax.microedition.contactless.TransactionListener;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
 
/**
 * Simple midlet that notifies the user about secure element activity in card
 * emulation mode.
 */
public class ShowExternalSEAccess extends MIDlet implements CommandListener,
        TransactionListener {
    /**
     * Form to show information about detected card
     */
    Form form = new Form("ShowExternalSEAccess");
 
    /**
     * Exit command
     */
    Command exitCmd = new Command("Exit", 1, Command.OK);
 
    /**
     * Constructor.
     */
    public ShowExternalSEAccess() {
        super();
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see javax.microedition.midlet.MIDlet#startApp()
     * 
     * Sets the form as current displayable and adds
     * transaction listener.
     */
    protected void startApp() throws MIDletStateChangeException {
        // Set form as current displayable
        form.addCommand(exitCmd);
        form.setCommandListener(this);
        Display.getDisplay(this).setCurrent(form);
 
        // Add transaction listener
        try {
            DiscoveryManager.getInstance().addTransactionListener(this);
        } catch (Exception ex) {
            // Show any exceptions if adding the target listener fails.
            form.append(ex.toString());
        }
    }
 
    protected void pauseApp() {
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
     * 
     * Remove the transaction listener when done.
     */
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        try {
            DiscoveryManager.getInstance().removeTransactionListener(this);
        } catch (Exception ex) {
            // Ignore exceptions at this point
        }
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see javax.microedition.contactless.TransactionListener#externalReaderDetected(byte)
     * 
     * This method is called after secure element activity in card emulation
     * mode. This notification informs the application, that there might be
     * changes in the data on the secure element.
     */
    public void externalReaderDetected(byte slot) {
        form.append("External reader detected, slot=" + slot
                    + (slot == TransactionListener.UNKNOWN_SLOT ?
                      " (UNKNOWN SLOT)\n" : "\n"));
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command,
     *      javax.microedition.lcdui.Displayable)
     * 
     * Handle exit command.
     */
    public void commandAction(Command c, Displayable d) {
        if (c == exitCmd) {
            exit();
        }
    }
 
    /**
     * Exit the midlet.
     */
    private void exit() {
        try {
            destroyApp(false);
            notifyDestroyed();
        } catch (MIDletStateChangeException ex) {
        }
    }
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
User::ResetInactivityTime() without backlight? davidmaxwaterman General Symbian C++ 2 2007-03-19 05:24
About CAs or how can i avoid it lfarady Near Field Communication 3 2007-10-05 13:44
Wrong data to internal 4k on block 3 of one of sector Alex_Polt Near Field Communication 9 2007-09-05 09:07
Loading Applet into NFC 6131 Secure Element lovercjs Near Field Communication 2 2007-10-23 16:28
Questions about security berroto Near Field Communication 2 2008-01-31 15:55
 
Powered by MediaWiki
RDF Facets: qfnZtopicQUqfnTopicZjavaQ qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX