Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Detect secure element activity

From Wiki
Jump to: navigation, search

Simple MIDlet that notifies the user about secure element activity in card emulation mode.

Article Metadata
Compatibility
Platform(s):
Series 40
Article
Created: tsavinen (27 Jun 2007)
Last edited: hamishwillee (23 Jul 2013)
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) {
}
}
}
This page was last modified on 23 July 2013, at 10:18.
47 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×