Tutorial

Tutorial

-

Documents
10 pages
Lire
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description





Tutorial

Hagenberg Linz Steyr Wels





NFC Jump Start
by Gerald Madlmayr
(version 1.1)


- 1 -




Tutorial

Hagenberg Linz Steyr Wels


Tools needed
Development Environment
Java SDK (J2SE): http://java.sun.com
Eclipse IDE: www.eclipse.org
Mobile Tools for Java (MTJ) Plugin for J2ME Development: http://www.eclipse.org/dsdp/mtj/
Antenna 1.1.0 beta: http://antenna.sourceforge.net/
Optional: Proguard: http://proguard.sourceforge.net/
SDKs for J2ME
Wireless Toolkit (WRT) 2.5.2_01: http://java.sun.com/products/sjwtoolkit/download.html
Nokia 6212 SDK: http://www.forum.nokia.com/info/sw.nokia.com/id/5bcaee40-d2b2-4595-b5b5-
4833d6a4cda1/S40_Nokia_6212_NFC_SDK.html
Setup
1) Install the Java SDK (J2SE)
2) Unzip and Install Eclipse
3) Install WRT & Nokia 6212 SDK onto your hard disk using the default settings.
4) Unzip and copy Antenna and Proguard Libraries onto your hard disk.
5) Integrate the MTJ Plugin for J2ME Development into Eclipse as stated here:
http://www.eclipse.org/dsdp/mtj/development/tutorial/gettingstarted.php; (you should already
met all the Prerequisites)
6) To integrate the J2ME-SDKs open the Preferences Dialogue form the Window Menu in Eclipse.
Select JAVA ME and Device Management. Click on Import and the Browse or specifiy the
directory where MTJ should look for your WRTs (eg: C:\WTK2.5.2_01 and C:\Nokia). After MTJ
has found the SDK press Select all and Finish. ...

Sujets

Informations

Publié par
Nombre de visites sur la page 273
Langue English
Signaler un problème
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
1
-
NFC Jump Start
by Gerald Madlmayr
(version 1.1)
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
2
-
Tools needed
Development Environment
Java SDK (J2SE):
http://java.sun.com
Eclipse IDE:
www.eclipse.org
Mobile Tools for Java (MTJ) Plugin for J2ME Development:
http://www.eclipse.org/dsdp/mtj/
Antenna 1.1.0 beta:
http://antenna.sourceforge.net/
Optional: Proguard:
http://proguard.sourceforge.net/
SDKs for J2ME
Wireless Toolkit (WRT) 2.5.2_01:
http://java.sun.com/products/sjwtoolkit/download.html
Nokia 6212 SDK:
http://www.forum.nokia.com/info/sw.nokia.com/id/5bcaee40-d2b2-4595-b5b5-
4833d6a4cda1/S40_Nokia_6212_NFC_SDK.html
Setup
1) Install the Java SDK (J2SE)
2) Unzip and Install Eclipse
3) Install WRT & Nokia 6212 SDK onto your hard disk using the default settings.
4) Unzip and copy Antenna and Proguard Libraries onto your hard disk.
5) Integrate the MTJ Plugin for J2ME Development into Eclipse as stated here:
http://www.eclipse.org/dsdp/mtj/development/tutorial/gettingstarted.php
; (you should already
met all the Prerequisites)
6) To integrate the J2ME-SDKs open the
Preferences
Dialogue form the Window Menu in Eclipse.
Select
JAVA ME
and
Device Management
. Click on
Import
and the Browse or specifiy the
directory where MTJ should look for your WRTs (eg: C:\WTK2.5.2_01 and C:\Nokia). After MTJ
has found the SDK press
Select all
and
Finish
. The Device list should look something like that
(please not to choose
All
from the
Installed SDKs
Drop-Down)
7) That’s it – let’s start with our first “HelloNFC” example.
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
3
-
Create a New Sample Project
1) File > New > Package
2) Select
MIDlet Project
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
4
-
3) Create a New Midlet Project
Project Name:
HelloNFC
Press Finish
4) Create a new Java Package
Package name.
at.nfcresearch
Press Finish.
5) File > New > Class
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
5
-
6) Create a new Java Class
Package name.
HelloNFC
Press Finish.
7) Copy & Paste Code form
Appendix to Java-File
8) Double Click
Application
Descriptor
9) Select
MIDlets
, then press
ADD
and enter
HelloNFC
as
Name and press
Browse
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
6
-
10) Choose
HelloNFC
and confirm
the selection with
OK
.
11) To execute the MIDlet in the
Emulator press the
Play Button
and select
Run As
and
Emulated
Java ME MIDlet
.
12)
Then the
6212 Emulator
as well as the
NFC Manager
Open automatically.
13) In order to read the ID of a Tag, just drop on of the predefined tags in the NFC
Manager to onto the phone in the NFC Manger and the Emulator will read the UID of
the Tag.
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
7
-
14) To check whether the J2ME worked correctly, right click the Tag in the NFC Manager
and select
Change UID
to determine the UID of the tag.
That’s it for the beginning. You have successfully tested your fist MIDlet in Nokia 6212 Emulator using
the NFC Manager.
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
8
-
More
Optional: NCF (Nokia Connectivity Framework):
http://www.forum.nokia.com/info/sw.nokia.com/id/fb0180d3-5b0b-43e4-8792-
147488267c2d/ncf_v1_2.zip.html?ticket=ST-83117-gDAluuZdYehqKCBXNIxadKDYfEahh7PKbXS-20
(requires Serial Number)
(if you plan to use the Nokia Connectivity Framework, please make sure you download a 1.4.x Version
of SDK).
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
9
-
Appendix
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
at.nfcresearch;
// Packages for contactless Communcation
import
javax.microedition.contactless.ContactlessException;
import
javax.microedition.contactless.DiscoveryManager;
import
javax.microedition.contactless.TargetListener;
import
javax.microedition.contactless.TargetProperties;
import
javax.microedition.contactless.TargetType;
import
javax.microedition.lcdui.Alert;
import
javax.microedition.lcdui.AlertType;
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;
public
class
HelloNFC
extends
MIDlet
implements
TargetListener, CommandListener {
// Display Components
// An Exit-Button
private
Command
exitCommand
;
// A Form to display the information
private
Form
form
;
public
HelloNFC() {
// Create the GUI
exitCommand
=
new
Command(
"Exit"
, Command.
EXIT
, 1);
form
=
new
Form(
"UIDClient"
);
form
.addCommand(
exitCommand
);
form
.append(
"Touch Tag to read ID."
);
// add a command Listern, to see when a button is pressed
form
.setCommandListener(
this
);
// Registration of the TargetListener for external contactless
// Targets (in this case RFID_TAG, as it is the most general type).
try
{
DiscoveryManager dm = DiscoveryManager.
getInstance
();
dm.addTargetListener(
this
, TargetType.
RFID_TAG
);
// in case the Listener can not be registered, throw an exception
}
catch
(ContactlessException ce) {
displayAlert(
"Unable to register TargetListener: "
+ ce.toString(), AlertType.
ERROR
);
}
}
// Method from MIDlet to start the Application
public
void
startApp() {
Display.
getDisplay
(
this
).setCurrent(
form
);
}
// Method from MIDlet to pause the Application
public
void
pauseApp() {
}
// Method from MIDlet to close the Application
public
void
destroyApp(
boolean
unconditional) {
}
/**
*
Implementation
of
the
Call
-
Back
Function
of
the
TargetListener
*
@param
targetProperties:
Array
of
Targets
found
by
the
Phone
*
*/
public
void
targetDetected(TargetProperties[] targetProperties) {
Tutorial
y
Hagenberg
y
Linz
y
Steyr
y
Wels
-
1
0
-
// in case no targets found, exit the method
if
(targetProperties.
length
== 0) {
return
;
}
// show the UID of the first tag found
TargetProperties tmp = targetProperties[0];
displayAlert(
"UID read: "
+ tmp.getUid(), AlertType.
INFO
);
// read ID
try
{
form
.append(
"ID read: "
+ tmp.getUid());
}
catch
(Exception e) {
form
.append(
"Error: "
+ e.toString());
}
}
/**
*
Implementation
of
the
Call
-
Back
function
of
the
CommandListener
*
@param
command:
command
key
pressed
*
@param
displayable:
associated
displayable
Object
*/
public
void
commandAction(Command command, Displayable displayable) {
if
(command ==
exitCommand
) {
// Deregister the TargetListener
DiscoveryManager dm = DiscoveryManager.
getInstance
();
dm.removeTargetListener(
this
, TargetType.
NDEF_TAG
);
destroyApp(
false
);
notifyDestroyed();
}
}
/**
*
Helper
Function
to
display
a
Pop
-
Up
in
the
Emulator
*
@param
error:
Message
as
Text
*
@param
type:
The
kind
of
Pop
-
up
to
be
displayed
*/
private
void
displayAlert(String error, AlertType type) {
Alert err =
new
Alert(
form
.getTitle(), error,
null
, type);
Display.
getDisplay
(
this
).setCurrent(err,
form
);
}
}