SlideShare uma empresa Scribd logo
1 de 71
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 11
Embedded JavaEmbedded Java
J2MEJ2ME
Tébourbi RiadhTébourbi Riadh
riadh.tebourbi@supcom.rnu.tnriadh.tebourbi@supcom.rnu.tn
http://www.slideshare.net/ter216/coursJ2ME
ProgramProgram
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 22
40 Hours40 Hours
14 Hours
20-22 Mai
14 Hours
20-22 Mai
14 Hours
16-19 June
14 Hours
16-19 June
12 Hours
June 23 Mai-15 June
12 Hours
June 23 Mai-15 June
Course
Application
exercises
Mini project
Exercises
Project
Project
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 33
JavaJava platformsplatforms
Java2
Standard Edition
(J2SE)
Java2
Standard Edition
(J2SE)
Java2
Enterprise Edition
(J2EE)
Java2
Enterprise Edition
(J2EE)
Java2
Micro Edition
(J2ME)
Java2
Micro Edition
(J2ME)
Java 2 Platform
Applications :
Standards desktop &
Workstation
Servers, Enterprise
Applications
Embedded devices Small &
memory constrained
devices
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 44
JavaJava EditionsEditions
- Each edition defines different sets of class
libraries.
Example for J2SE
Java SE 7 2011 : 3 977
Java SE 6 2007 : 3 777
J2SE 5.0 2004 : 3 270
J2SE 1.4 2002 : 2 723
J2SE 1.3 2000 : 1 840
J2SE 1.2 1998 : 1 524
JDK 1.1 1997 : 477
JDK 1.0 1996 : 211
 There are thousands of core J2SE runtime
classes, taking up to 10-20 megabytes of space.
- J2ME-based devices have fewer classes.
J2ME
J2SE
J2EE
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 55
What is Java 2 Micro Edition?What is Java 2 Micro Edition?
 A JAVA platform for limited resources devicesA JAVA platform for limited resources devices
 A subset of J2SEA subset of J2SE
 Target devices:Target devices:
 Mobiles phones, Smart PhonesMobiles phones, Smart Phones
 PDAs, PocketPCPDAs, PocketPC
 TV, VCR, CD playersTV, VCR, CD players
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 66
Embedded devicesEmbedded devices Small & memorySmall & memory
constrained devicesconstrained devices
_ SmartCard
_ Cellular Phone
_ PocketPC
_ eBook
_ Digital photo device
_ Set Top Box
_ TV
_ DVD, CD, Blu-ray player
_ Game Console
_ Electronic Consuming
_ Payment terminal, ATM, Parking Meter
_ Printer
_ Car
J2ME architectureJ2ME architecture
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 77
How to meet the requirements for a broad range of devices within target markets ?
J2ME architecture defines combinations of configurations, profiles, and optional
packages as elements for building complete Java runtime environments :
a configuration provides the most basic set of libraries and virtual machine capabilities for
a broad range of devices,
a profile is a set of APIs that support a narrower range of devices
an optional package is a set of specific APIs.
 Each combination is optimized for the memory, processing power, and I/O capabilities
of a related category of devices.
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 88
ConfigurationsConfigurations
Define the base characteristics of a runtime environment for a certain type of devices with
similar set of characteristics and resources. They consist of a virtual machine and a basic
set of APIs.
2 base configurations:
CLDC (Connected Limited Device Configuration): to fit small mobile devices
CDC (Connected Device Configuration) : target towards more capable mobile devices
like smart-phones and set top boxes
CDC & CLDCCDC & CLDC
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 99
Connected Limited Device Configuration (CLDC):
- CLDC is the smaller of the two configurations.
- It is designed for devices with intermittent network connections, slow processors
and limited memory. Typical examples: Mobile phones Two-way pagers,
PDAs,
- These devices typically have either 16-bit or 32-bit CPUs, and a minimum of 128
KB to 512 KB of memory for the Java platform implementation and associated
applications.
- KVM as VM
Connected Device Configuration (CDC):
- CDC is designed for devices that have more memory, faster processors, and
greater network bandwidth, such as
- TV set-top boxes, residential gateways
- in-vehicle telematics systems, and high-end PDAs….
- Most CDC-targeted devices have 32-bit CPUs and a minimum of 2MB of memory.
- CVM as VM
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1010
ProfilesProfiles
Consist of a set of APIs for a specific device type or a specific feature. They allow the use of
specific features and should be associated with a configuration. They used to provide modularity to
the J2ME platform. (profile = minimum set of APIs for similar devices)
Profil Configuration  
MIDP 1.0  CLDC Package javax.microedition.*
MIDP 2.0  CLDC Basic profile
PDA CLDC
PDAs that have better screens and more memory than cell
phones.
Mobile Media API (MMAPI) : optional package  CLDC Play audio and vidéo
Wireless Messaging API (WMA): optional package  CLDC Send & receive SMS
Java APIs for Bluetooth: optional package  CLDC Bluetooth
Foundation Profile  CDC
Include almost all of the core Java 2 Version 1.3 core
libraries
Personal Basis Profile CDC
Adds basic user interface functionality to the Foundation
Profile
Personal Profile  CDC Platforms that can support a more complex user interface
RMI optional package CDC Remote Method Invocation
JDBC optional package  CDC  Java Database Connectivity (JDBC) API
J2ME Web Services: optional package CDC Web Services
Mobile 3D Graphics API for J2ME CDC 3D
Game profile CDC Game app development
Configurations, profiles & optional packagesConfigurations, profiles & optional packages
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1111
Mobile Service Architecture (MSA)
JSR: Java Specification Requests
 https://jcp.org/en/jsr/tech?listBy=1&listByType=platform
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1212
ExamplesExamples
Manufacturer Model
Wireless
Technology
Frequency
(MHz)
Software Screen
Alcatel One Touch 735i E-GSM, GSM 900, 1800 MIDP 2.0, WMA 1.0,
CLDC 1.0
128x128/12 bits
Motorola A388c GSM/GPRS 900, 1800, 1900 MIDP 1.0, CLDC 1.0 240x320/16 bits
Motorola A760 MIDP 2.0, CLDC 1.0 320x240/16 bits
Motorola T720i GSM/GPRS 1900 MIDP 1.0, CLDC 1.0 120x160/12 bits
Nokia 3100 GSM/GPRS 900, 1800, 1900 MIDP 1.0, WMA 1.0,
CLDC 1.0
128x128/12 bits
Nokia 3200 GSM/GPRS/EDGE 900, 1800, 1900 MIDP 1.0, WMA 1.0,
CLDC 1.0
128x128/12 bits
Nokia 5140 GSM 900, 1800, 1900 CLDC 1.1, MIDP 2.0 128x128/12 bits
Nokia 9500 GSM, GSM/GPRS 850, 900, 1800, 1900 JTWI 1.0, M3DAPI 1.0,
CLDC 1.1, MIDP 2.0,
MMAPI 1.1, LAPI 1.0,
WMA 1.1
640x200/16 bits
Nokia 7610 GSM 850, 900, 1800, 1900 MIDP 1.0, MIDP 2.0,
CLDC 1.0
176x208/16 bits
Samsung SGH-S100 GSM/GPRS 900, 1800, 1900 MIDP 1.0, CLDC 1.0 128x160/16 bits
Siemens C55 GSM/GPRS 900, 1800 MIDP 1.0, CLDC 1.0 101x64/1 bit
Siemens S6V GSM/GPRS 900, 1800, 1900 JTWI 1.0, M3DAPI 1.0,
CLDC 1.1, MIDP 2.0,
MMAPI 1.1, LAPI 1.0,
JABWT 1.0, WMA 1.1
132x176/16 bits
Sony Ericsson P908 GSM/GPRS 900, 1800, 1900 MIDP 2.0, PersonalJava
1.1.1, JABWT 1.0, CLDC
1.0, WMA 1.1
208x320/16 bits
Before you can develop a mobile application you must know the configuration and profiles it
can support:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1313
MIDP ProfileMIDP Profile
(Mobile Information Device Profile)(Mobile Information Device Profile)
•128KB of non-volatile memory for the MIDP implementation
•32KB of volatile memory for the runtime heap
•8KB of non-volatile memory for persistent data
•A screen of at least 96 × 54 pixels
•Some capacity for input, either by keypad, keyboard, or touch screen
•Two-way network connection, possibly intermittent
http://java.sun.com/products/midp/ :
MIDPMIDP is for a set of devices known asis for a set of devices known as mobile information devicesmobile information devices
(MIDs). Minimal characteristics of MIDs:(MIDs). Minimal characteristics of MIDs:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1414
MIDP ApplicationMIDP Application
 MIDP does not support the running of applicationsMIDP does not support the running of applications
that use a static main method as their entry point,that use a static main method as their entry point,
nor calling the System.exit method in order tonor calling the System.exit method in order to
terminate.terminate.
 Instead, we use aInstead, we use a MIDletMIDlet, which is a MIDP, which is a MIDP
application.application.
MIDlet life cycleMIDlet life cycle
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1515
•The life-cycle defines the execution states
of a MIDlet : creation, start, pause, and exit 
•The application management software
(AMS) is the software on a device that
manages the downloading and life-cycle of
MIDlets.
•The AMS provides the runtime environment
for a MIDlet. It enforces security,
permissions, and execution states.
Constructor
startApp(
)
pauseApp
()
destroyApp()
destroyApp()
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1616
MIDlet programmingMIDlet programming
 A MIDP application must be a sub-class of MIDletA MIDP application must be a sub-class of MIDlet
class:class:
public class MyMidlet extends MIDlet {…}public class MyMidlet extends MIDlet {…}
 Equivalent MIDP of an applet, where the executionEquivalent MIDP of an applet, where the execution
and the stop are controlled by theand the stop are controlled by the applicationapplication
management softwaremanagement software
 When a MIDlet is executed the AMS calls ltheWhen a MIDlet is executed the AMS calls lthe
method MIDlet.startApp() after the constructormethod MIDlet.startApp() after the constructor
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1717
Architecture of a MIDletArchitecture of a MIDlet
public class MyMidlet extends MIDlet {
public MyMidlet() {
//the constructor
}
public void startApp() {
// MyMidlet it starts here (after the constructor)
}
public void pauseApp() {
// MyMidlet is now in “pause” mode (no display)
}
public void destroyApp(boolean unconditional) {
// MyMidlet is destroyed, clean if necessary
}
}
UI Programming ModelUI Programming Model
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1818
 The central abstraction is a screen
 Only one screen may be visible at a time
 Three types of screens:
 Predefined screens with complex UI
components (List, TextBox)
 Generic screens (Form where you can add
text, images, etc)
 Screens used with low-level API (Canvas)
 The Display class is the display manager
 It is instantiated for each active MIDlet
 Provides methods to retrieve information about the device’s
display capabilities.
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1919
APIAPI UI Programming ModelUI Programming Model
ScreenCanvas
Form TextBoxListBox ItemAlert
ChoiceGroup DateField Gauge ImageItem StringItem TextField
Displayable
Low level API (game)
High level API (GUI)
DisplayDisplay
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2020
Display manages device’s screen
 Use getDisplay() (static method of Display) to access the display - in the startApp()
method for example
 Use the returned Display object to determine device capabilities or current displayable
 isColor()  color or grayscale device
 numColors()  number of colors supported
 numAlphaLevels()  number of transparency level
 getCurrent()  a reference to what (displayable) currently being shown

After creating something to show as an instance of Displayable you can display it:
 setCurrent(Displayable next)
 setCurrent(Alert alert, Displayable nextDisplayable)
Librairies de base de MIDPLibrairies de base de MIDP
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2121
 Interface utilisateurInterface utilisateur
 javax.microedition.lcduijavax.microedition.lcdui L’environnement de base d’interface utilisateur.L’environnement de base d’interface utilisateur.
 javax.microedition.lcdui.gamejavax.microedition.lcdui.game Facilite le développement de jeux sur mobile.Facilite le développement de jeux sur mobile.
 PersistencePersistence
 javax.microedition.rmsjavax.microedition.rms Un mécanisme simple et sécurisé de persistence.Un mécanisme simple et sécurisé de persistence.
 Application Lifecycle PackageApplication Lifecycle Package
 javax.microedition.midletjavax.microedition.midlet Définit l’interaction entre l’application est l’environnementDéfinit l’interaction entre l’application est l’environnement
 RéseauRéseau
 javax.microedition.iojavax.microedition.io La gestion des connexions.La gestion des connexions.
 AudioAudio
 javax.microedition.mediajavax.microedition.media Les outils de base pour créer un player.Les outils de base pour créer un player.
 javax.microedition.media.controljavax.microedition.media.control La commande du player.La commande du player.
 Public KeyPublic Key
 javax.microedition.pkijavax.microedition.pki Gestion des certificats utilisés en connexion sécurisée.Gestion des certificats utilisés en connexion sécurisée.
 Core PackagesCore Packages
 java.iojava.io Gestion des entrées sorties au travers des DataStreams..Gestion des entrées sorties au travers des DataStreams..
 java.langjava.lang Les classes de base de Java.Les classes de base de Java.
 java.utiljava.util les collection classes, la date et le temps..les collection classes, la date et le temps..
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2222
1/2
Un premier Exemple
HelloSupcomMIDlet.java
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2323
2/2
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2424
 Afficher un texte qui défile: utilisation de la classe Ticker: HelloSupcomMIDletbis.java
…..Pour la Suite voir HelloSupcomMIDlet
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2525
Un deuxième Exemple 1/2
SimpleListe1.java
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2626
2/2
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2727
list = new List("Sample list", List.IMPLICITList.IMPLICIT, …);
Remarque sur le constructeur de la classe List: new List(String title, int listTypeint listType, …)
list = new List("Sample list", List.EXCLUSIVEList.EXCLUSIVE, …);
list = new List("Sample list", List.MULTIPLEList.MULTIPLE, …);
(SimpleListe1.java)
(SimpleListe2.java)
(SimpleListe3.java)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2828
Action après choix dans une liste: troisième Exemple: SimpleListe4.java 1/2
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2929
2/2
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3030
Forms et ItemsForms et Items
 Form (class) est le seul "container" dans MIDPForm (class) est le seul "container" dans MIDP
 Form contient des objets Item (class) (doc API:Form contient des objets Item (class) (doc API: A superclass forA superclass for
components that can be added to a Formcomponents that can be added to a Form))
 Les éléments sont ajoutés en utilisant Form.append()Les éléments sont ajoutés en utilisant Form.append()
 form.append(item);form.append(item);
 form.append("string");form.append("string");
 Quand un Item change d’état (suite à une action sur celui-ci), ilQuand un Item change d’état (suite à une action sur celui-ci), il
génère l’événement ItemStateChangedgénère l’événement ItemStateChanged
 Capté par un ItemStateListener définit sur la FormCapté par un ItemStateListener définit sur la Form
 Le changement d’état appelle la méthode ItemStateListenerLe changement d’état appelle la méthode ItemStateListener
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3131
Diagramme des ItemsDiagramme des Items
• 1 Form peut avoir plusieurs Items (components)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3232
Example 4 (1/2)Example 4 (1/2)
Form1.javaForm1.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Form1 extends MIDlet implements ItemStateListener {
protected Display display;
protected Form form;
public Form1() {
display = Display.getDisplay(this);
form = new Form("Info entry form");
form.append(new TextField("Name", "", 10, TextField.ANY));
form.append(new Gauge("Age (0-100)", true, 10, 2));
form.append(new ChoiceGroup("Job", Choice.EXCLUSIVE,
new String[] {“active", "student"}, null));
form.setItemStateListener(this);
}
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3333
Example 4 (2/2)Example 4 (2/2)
public void itemStateChanged(Item item) {
// if an item changes – it gets sent here!
System.out.println("State changed on item "
+ item.toString());
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
display = null;
form = null;
}
}
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3434
Image et ImageItemImage et ImageItem
•Classes pour manipuler des images
•Image: classe pour créer un objet image et contient des
attributs tels que Hauteur Largeur de l’image.
•ImageItem: sert pour afficher l’image sur une Form. Elle définit
comment l’image va être afficher à l’écran (à gauche, centrée,
taille, etc..)
•MIDP offre deux types d’images:
• immutable: ne peut pas être modifiée après création (une
image lue d’un fichier image par exemple)
•mutable : une image créée et stockée en mémoire par
l’utilisateur.
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3535
Affichage d’une imageAffichage d’une image
ImageItem(String label, Image img, int layout, String altText)
Constructeurs:Constructeurs:
Image createImage(String name)
Form fmMain = new Form("Images");
...
// Create an image
Image img = Image.createImage("/supcom.png");
// Append to a form
fmMain.append(new ImageItem(null, img, ImageItem.LAYOUT_CENTER, null));
Affichage sur une Form:Affichage sur une Form:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3636
Exemple 5 (1/2)Exemple 5 (1/2)
HelloSupcomMIDletfin.javaHelloSupcomMIDletfin.java
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3737
Exemple 5 (2/2)Exemple 5 (2/2)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3838
Les ThreadsLes Threads
•Utilisés pour faire du multitâche:
Pendant la lecture d’une vidéo, l’interface graphique d’une application est
fonctionnelle
Lors d’une animation ont peut écouter la musique.
•Thread = unité d'exécution faisant partie d'un programme. Cette unité fonctionne de façon
autonome et parallèlement à d'autres Threads. chaque unité se voit attribuer des intervalles
de temps au cours desquels elles ont le droit d'utiliser le processeur pour accomplir leurs
traitements
•Un programme (ou partie d’un programme) java peut être mis sous un Thread.
•Le principal avantage des Threads est de pouvoir répartir différents traitements d'un
même programme en plusieurs unités distinctes pour permettre leur exécution
"simultanée".
•La classe java.lang.Thread et l'interface java.lang.Runnable sont les bases pour le
développement des Threads en java. Par exemple, pour exécuter des Midlets dans un
thread, il faut que celles ci implémentent l'interface Runnable.
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3939
Les ThreadsLes Threads
1) public class MaMidlet extends MIDlet implements CommandListener, Runnable
{….}
Création d’un Thread dans une Midlet
2) public Thread(Runnable target)
//Allocates a new Thread object with a specific target object whose run method is called.
//Créer un objet Thread pour un autre objet “target” (une Midlet par exemple) et c’est la
//methode run() de “target” qui sera exécutée.
Thread t = new Thread(this)
t.start(); apple de la méthode surchargée run();
3) //implementation de la méthode run() de la Midlet:
public void run() {
…..//faire un traitement long
}
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4040
Les ThreadsLes Threads
Création d’un Thread pour une méthode
Une méthode d’une Midlet peut être mise sous un Thread indépendant. Elle sera exécuter
alors en parallèle avec la Midlet.
private void doSomethingBig() {
new Thread() {
public void run() {
…….//do something big
}
}.start();
}
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4141
MIDP 2.0MIDP 2.0
Quoi de neuf ? (disponible été 2003)
• UI
•Multimédia :Mobile Media API (MMAPI)
•Amélioration des formulaire
•Images RGB
• Game API
javax.microedition.lcdui.game
GameCanvas, LayerManager, Layer,
TiledLayer, Sprit
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4242
MIDP 2.0MIDP 2.0
• Sécurité
• HTTPS
• PKI (Certificats)
• JAR signé
La signature et la clé publique sont ajoutés au JAD
• Permissions
Nouvelles entrées du JAD : MIDIet-Permissions, MIDIet-Permissions-Op
• Lancement Push de MIDLet sur des demandes entrantes
de connexions réseaux
• L'entrée MIDlet-Push-<n> du JAD précise:
l’URL local de connection URL
la classe de la MIDLet
l’adresse IP de la machine autorisée à lancer un push
• Exemple : MIDIet-Push-1: socket://:76, exemple.PushLet. 192.161.60
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4343
MessagingMessaging
• Wireless Messaging API (WMA) pour J2ME
Messageries pour « pager » et téléphone mobile
• WMA 1.1 (JSR 120) permet l’envoie et la réception de SMS
(Short Message Service)
ou de CBS (Cell Broadcast Service)
• WMA 2.0 (JSR 205) prend en compte l’envoies MMS
Wireless Messaging API (WMAWireless Messaging API (WMA
2.0)2.0)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4444
Message: classe de base pour définir un message. C’est une superclasse pour des
types de messages BinaryMessage (fichier wav par exemple), MultipartMessage
(message en plusieurs parties) et textMessage (message texte).
MessageConnection: fournie les fonctionnalités de base pour créer, envoyer et
recevoir les messages.
package, javax.wireless.messaging
Wireless Messaging API (WMAWireless Messaging API (WMA
2.0)2.0)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4545
MessageListener: Interface pour définir un “listener” et permet d’implémenter des
notifications asynchrones des messages reçus
MessagePart: permet de définir une partie a ajouter à un message ayant plusieurs
parties (MultipartMessage).
 smsExemple.java
Record Management StoreRecord Management Store
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4646
API qui permettent aux applications MIDP la persistance sur les appareils.
Record Management System (RMS), un espace mémoire pour les MIDlets
Record Store: RS
- Fichiers binaires dépendants de la plateforme car ils sont créés dans des
répertoires dépendants de la plateforme
- une collection d’enregistrements avec un clé primaire unique (integer)
- L’ ID d’un enregistrement
du premier enregistrement = 1
un compteur incrémenté de 1 à chaque création d’un enregistrement.
javax.microedition.rms
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4747
MultimédiaMultimédia
•Mobile Media API (MMIA)
•Son,MIDI, Vidéo, streaming…
•En remplacement de JMF (trop gros 650k, awt)
•Compact: 150K (MIDI, MPEG1, MP3,…)
MIME Type Description
audio/midi MIDI files
audio/sp-midi Scalable Polyphony MIDI
audio/x-tone-seq MIDP 2.0 tone sequence
audio/x-wav WAV PCM sampled
audio
image/gif GIF 89a (animated GIF)
video/mpeg MPEG video
video/vnd.sun.rgb565 Video capture
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4848
Mobile Media API (MMIA)
Introduction
Spécificités:
•Support pour “Génération de tonalité”, “Playback”, et
“enregistrement/capture multimédia”: l’API accepte tout contenu
audio et vidéo.
•Tien compte des contraintes de mémoire sur des plateformes
CLDC
•Extensible: Nouvelles fonctionnalités peuvent être rajoutées;
d’autres formats de contenu audio, vidéo peuvent être supportés.
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4949
Gestion/Traitement du contenu
Deux parties:
•Gestion du protocole (Protocol Handling): Lire les données d’une source, exemple:
fichier, serveur(réseau), streaming.
•Gestion du contenu(Content Handling): une fois lu, le contenu est décodé et
restitué via une sortie du périphérique (haut parleur pour le son, écran pour la
vidéo)
 Trois classes:
•Player: Lit les données d’une source, les traites et
les restitue.
•Manager: Pour créer des players, jouer des
tonalités, contient les protocoles et les types de
contenus que le mobile supporte.
•DataSource: Définit comment des données d’une
source (fichier, http, rtp) sont lues. On peut créer un
nouveau DataSource (pour un nouveau format par
exemple)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5050
ManagerManager
C’est la classe centrale pour creéer des “players” et offre trois methodes pour
indiquer la source de données:
createPlayer(DataSource source)
createPlayer(InputStream stream, String type)
createPlayer(String locator)createPlayer(String locator)
Player p = Manager.createPlayer("capture://video");
Player p = Manager.createPlayer ("http://nokia.com/chanson.mp3");
Player p = Manager.createPlayer("http://movies.com/film.mpg");
Type Media Exemple syntaxe
Capture audio
"capture://audio" : capture audio sur périph défaut.
"capture://devmic0?encoding=pcm" capture audio sur devmic0 avec encodage
PCM.
Capture vidéo
"capture://video" : capture video à partir du périphérique de capture par défaut
"capture://devcam0?encoding=rgb888&width=100&height=50" :
capture d’une camera, rgb888 mode encodage, avec “width” “height” (taille)
spécifiques
Radio "capture://radio?f=105.1&st=stereo " : tuner à la fréquence 105.1 FM mode stéréo.
Streaming vidéo/audio/texte d’une source externe "rtp://host:port/type" : type = audio, vidéo ou texte
Jouer des tonalités/ MIDI
"device://tone" :player pou jouer des tonalités
"device://midi" :ou MIDI
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5151
PlayerPlayer
•Créé avec Manager
•Permet de restituer un contenu multi-media
•Possède des états: UNREALIZED, REALIZED, PREFETCHED, STARTED, et CLOSED
UNREALIZED: état initial, juste après création
REALIZED: initialise les infos sur les medias (type,
périphériques de captures, etc).
PREFETCHED: établis la connexions avec la média et la
charge, établit les connections réseau pour le streaming.
STARTED: la lecture a commencé (mode lecture)
CLOSED: arrêt de lecture, arrêt du lecteur
•realize()
•prefetch()
•start()
•stop()
•deallocate()
•close()
Passage d’un état à un
autre:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5252
Player(2)Player(2)
•On associe à un lecteur un contrôle (control) : une fonctionnalité média spécifique.
•Examples:
VideoControl: obtient et contrôle la fenêtre vidéo
MIDIControl, ToneControl: accès aux propriétés MIDI/Tonalités du périphérique.
VolumeControl: contrôle du volume
Player p; Form frm;
vc = (VideoControl)p.getControl("VideoControl");
volc = (VolumeControl)p.getControl("VolumeControl");
frm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null)); //Ajout de la
fenêtre vidéo sur une forme en tant que Item.
volc.setLevel(50); //Volume à 50 (entre 0 et 100)
•Usage:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5353
Exemple 1 (1/2)Exemple 1 (1/2)
VideoPlayer.javaVideoPlayer.java
Lecture d’un fichier vidéo
stocké sur un serveur
(exmple apache Tomcat).
Url:
http://localhost/midp/shark.
mpg
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5454
Exemple 6 (2/2)Exemple 6 (2/2)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5555
Exemple 7 (1/2)Exemple 7 (1/2)
VideoPlayer1.javaVideoPlayer1.java
…..
…..
Lecture d’un fichier vidéo à partir de l’archive jar. Utilisation de
Manager. createPlayer(InputStream stream, String type)
L’InputStream est obtenu à partir de l’objet application obtenu par
getClass()
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5656
Snapshot (capture d’une image)Snapshot (capture d’une image)
Vidéo lue  capturer une image
byte[] getSnapshot(java.lang.String imageType)
Méthode getSnaphot sur un objet VideoControl
snapshot = vc.getSnapshot("encoding=jpeg");
VideoControl vc;
byte[] snapshot;
ImageItem imi;
Image im = Image.createImage(snapshot, 0, snapshot.length);
 On obtient un objet Image qu’on peut afficher à l’aide d’un
ImageItem (voir exemple 5)
Exemple:
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5757
ApplicationApplication
EN TP:
MIDlet qui lit une vidéo depuis un URL dans une
liste
Fonctions Play, Pause et Stop (utilisation d'un
thread pour play)
Fonction Snapshot (produire une image à partir de
la vidéo) (un autre thread)
Fonction contrôle volume (utilisation de Gauge)
Fonction partage URL avec un ami par SMS
Fonction sauvegarder/charger les URLs dans la
mémoire du mobile (RMS)
VideoPlayer2.javaVideoPlayer2.java VideoPlayer3.javaVideoPlayer3.java
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5858
DéploiementDéploiement
Une Midlet java peut être déployée sur un périphérique mobile:
1) Directement par liaison USB, Série, Blutooth.. entre un PC et le Mobile
• Utilisation d’un logiciel de téléchargement (Oxygène phone manager,
NOKIA phone manager,..)
2) OTA: Over The Air: Téléchargement à partir d’un serveur.
• Utilisation d’un URL = adresse de la Midlet (Acces à travers le
réseau), exemple: http//nokia.com
•Sur le mobile: le « Application ManagerApplication Manager » gère l’installation, mise à jour,
désinstallation et exécution des applications java (un mini SE)
Dans les deux cas : il faut créer un package d’installation .jar (archive) {.class , images,
fichiers etc..} et .jad (description))
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5959
ExempleExemple
MIDlet-1: HelloSupcomMIDletfin, , HelloSupcomMIDletfin
MIDlet-Jar-Size: 66756
MIDlet-Jar-URL: http://localhost:8080/midp/hello1.jar
MIDlet-Name: hello1
MIDlet-Vendor: Tebourbi Riadh
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
hello1.jad
(En locale copier hello1.jar et hello1.jad sur le mobile (par liaison USB, Blutooth
etc..) et exécuter hello1. )
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6060
Exemple OTA(1)Exemple OTA(1)
Sur le SERVEUR
URL: http://ip_serveur/midp/hello1.html
<html>
<head>
<title>hello1</title>
</head>
<body>
<a href="http://localhost:8080/midp/hello1.jad">hello1.jad</a>
</body>
</html>
Hello1.html
•Copier les fichiers .jar et .jad dans le répertoire des applications WEB
•Écrire hello1.html qui contient un lien vers hello1.jad
•Exemple de serveur: Tomcat
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6161
Exemple OTA(2)Exemple OTA(2)
Sur le Mobile
1 2 3 4
5 6 7 8
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6262
Outils de développementOutils de développement
 Quelques outils:Quelques outils:
 J2ME Wireless Toolkit 2.0.1J2ME Wireless Toolkit 2.0.1
 Sun ONE Studio Mobile Edition 5Sun ONE Studio Mobile Edition 5
 CodeWarrior Wireless Studio 7.0CodeWarrior Wireless Studio 7.0
 Nokia Developer’s Suite Beta J2MENokia Developer’s Suite Beta J2ME
 RIM BlackBerry JDE 3.2RIM BlackBerry JDE 3.2
 Motorola LWT1.0Motorola LWT1.0
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6363
Sun ONE Studio Mobile EditionSun ONE Studio Mobile Edition
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6464
BlackBerry Java DevelopmentBlackBerry Java Development
EnvironmentEnvironment
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6565
Nokia Developer’s Suite &Nokia Developer’s Suite &
CodeWarriorCodeWarrior
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6666
J2ME Wireless ToolkitJ2ME Wireless Toolkit
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6767
InstallationInstallation
j2me_wireless_toolkit-2_2-windows.exe. Installation dans c:/wtk22
Applications Midlets
.jar, .jad
Midlet hello1
Les .class
Ressources de l’application:
exemple: supcom_rgb.png
Codes sources, exemple:
HelloSupcomMIDletfin.java
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6868
Création d’une Midlet(1)Création d’une Midlet(1)
« DémarrerprogrammesJ2ME Wireless Toolkit 2.2KToolbar »
NewProject: hello
« Settings »
Nom
Nom classe
(fichier .java)
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6969
Création d’une Midlet(1)Création d’une Midlet(1)
Nous allons tester la Midlet « HelloSupcomMIDlet » (exemple 1)  Le répertoire
C:WTK22appshellosrc doit contenir le fichier HelloSupcomMIDlet.java
Ecrire le fichier HelloSupcomMIDlet.java (à l’aide d’un éditeur de texte, ou
KAWA). Le copier dans le répertoire C:WTK22appshellosrc
Compiler: « ProjectBuild »
Exécuter: « ProjectRun »: exécution sur l’émulateur
JAR: « Projectpackagecreate package »: création du .jar
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 7070
Création d’une deuxième MidletCréation d’une deuxième Midlet
Nous allons rajouter au projet hello une deuxième midlet: HelloSupcomMIDletbis
Ecrire le fichier HelloSupcomMIDletbis.java (à l’aide d’un éditeur de texte, ou
KAWA). Le copier dans le répertoire C:WTK22appshellosrc
Dans « Settings »  « Midlets »  « Add »
entrer le nom de la midlet et la nom de la classe
(HelloSupcomMIDletbis)  « OK »
Build + RUN 
Exécution avec choix
Midlet à exécuter
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 7171
A VOUS DE JOUERA VOUS DE JOUER

Mais conteúdo relacionado

Destaque

Internet and Politics
Internet and PoliticsInternet and Politics
Internet and Politics
lizpuzio
 

Destaque (20)

Gsm Vs Cdma
Gsm Vs CdmaGsm Vs Cdma
Gsm Vs Cdma
 
6.2 Propagacion de oonda en linea de transmision
6.2 Propagacion de oonda en linea de transmision6.2 Propagacion de oonda en linea de transmision
6.2 Propagacion de oonda en linea de transmision
 
Programmation sous Android
Programmation sous AndroidProgrammation sous Android
Programmation sous Android
 
Gsm channel calculations
Gsm channel calculationsGsm channel calculations
Gsm channel calculations
 
4.TDM Multiplexacion por division de tiempo
4.TDM Multiplexacion por division de tiempo4.TDM Multiplexacion por division de tiempo
4.TDM Multiplexacion por division de tiempo
 
6.3 Propagacion de onda en el espacio libre
6.3 Propagacion de onda en el espacio libre6.3 Propagacion de onda en el espacio libre
6.3 Propagacion de onda en el espacio libre
 
3.PCM Digitalizacion de señal analogica
3.PCM Digitalizacion de señal analogica3.PCM Digitalizacion de señal analogica
3.PCM Digitalizacion de señal analogica
 
Cdma ppt for ECE
Cdma ppt for ECECdma ppt for ECE
Cdma ppt for ECE
 
6.6 Calculos de radioenlaces
6.6 Calculos de radioenlaces6.6 Calculos de radioenlaces
6.6 Calculos de radioenlaces
 
6.1 Ecuaciones de Maxwell
6.1 Ecuaciones de Maxwell6.1 Ecuaciones de Maxwell
6.1 Ecuaciones de Maxwell
 
2.Datos y señales en comunicaciones electrónicas
2.Datos y señales en comunicaciones electrónicas2.Datos y señales en comunicaciones electrónicas
2.Datos y señales en comunicaciones electrónicas
 
Nokia kpi and_core_optimization
Nokia kpi and_core_optimizationNokia kpi and_core_optimization
Nokia kpi and_core_optimization
 
Нормативные документы, необходимые для электронного документооборота в органи...
Нормативные документы, необходимые для электронного документооборота в органи...Нормативные документы, необходимые для электронного документооборота в органи...
Нормативные документы, необходимые для электронного документооборота в органи...
 
Анализ международного законодательства и правого опыта использования открытых...
Анализ международного законодательства и правого опыта использования открытых...Анализ международного законодательства и правого опыта использования открытых...
Анализ международного законодательства и правого опыта использования открытых...
 
Deans-textbook-alternatives
Deans-textbook-alternativesDeans-textbook-alternatives
Deans-textbook-alternatives
 
Internet and Politics
Internet and PoliticsInternet and Politics
Internet and Politics
 
Why
WhyWhy
Why
 
Burgerinitiatieven in Nederland (Paul Dekker)
Burgerinitiatieven in Nederland (Paul Dekker)Burgerinitiatieven in Nederland (Paul Dekker)
Burgerinitiatieven in Nederland (Paul Dekker)
 
Programming 101
Programming 101Programming 101
Programming 101
 
Economics 3.2
Economics 3.2Economics 3.2
Economics 3.2
 

Semelhante a Cours J2ME

Java ME by Amdane Samb at BarCamp Goree, December 2010
Java ME by Amdane Samb at BarCamp Goree, December 2010Java ME by Amdane Samb at BarCamp Goree, December 2010
Java ME by Amdane Samb at BarCamp Goree, December 2010
Christelle Scharff
 
Fichier_Compétences
Fichier_CompétencesFichier_Compétences
Fichier_Compétences
Yang Fei
 
Chap 1 Intro Microcontroleurs et Interruptions.pdf
Chap 1 Intro Microcontroleurs et Interruptions.pdfChap 1 Intro Microcontroleurs et Interruptions.pdf
Chap 1 Intro Microcontroleurs et Interruptions.pdf
DAPcreat
 
ALT.Net Montréal: NETMF et Gadgeteer
ALT.Net Montréal: NETMF et GadgeteerALT.Net Montréal: NETMF et Gadgeteer
ALT.Net Montréal: NETMF et Gadgeteer
Gabriel Mongeon
 

Semelhante a Cours J2ME (20)

Java ME by Amdane Samb at BarCamp Goree, December 2010
Java ME by Amdane Samb at BarCamp Goree, December 2010Java ME by Amdane Samb at BarCamp Goree, December 2010
Java ME by Amdane Samb at BarCamp Goree, December 2010
 
Chapitre 3 sem
Chapitre 3 semChapitre 3 sem
Chapitre 3 sem
 
Informatique Mobile et synchronisation
Informatique Mobile et synchronisationInformatique Mobile et synchronisation
Informatique Mobile et synchronisation
 
S7200 system manual_fr-fr
S7200 system manual_fr-frS7200 system manual_fr-fr
S7200 system manual_fr-fr
 
S21 les dernières nouveautés php sous ibm i (zend server 8.5 et zend studio...
S21   les dernières nouveautés php sous ibm i (zend server 8.5 et zend studio...S21   les dernières nouveautés php sous ibm i (zend server 8.5 et zend studio...
S21 les dernières nouveautés php sous ibm i (zend server 8.5 et zend studio...
 
Déployer une infrastructure de stockage en quelques minutes – IBM Spectrum Ac...
Déployer une infrastructure de stockage en quelques minutes – IBM Spectrum Ac...Déployer une infrastructure de stockage en quelques minutes – IBM Spectrum Ac...
Déployer une infrastructure de stockage en quelques minutes – IBM Spectrum Ac...
 
Diapo zig bee_amin_jan11_final
Diapo zig bee_amin_jan11_finalDiapo zig bee_amin_jan11_final
Diapo zig bee_amin_jan11_final
 
Connected Car Platform (CC-p)
Connected Car Platform (CC-p) Connected Car Platform (CC-p)
Connected Car Platform (CC-p)
 
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseriesBreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
BreizhCamp 2019 - IoT et open source hardware pour la collecte de timeseries
 
OpenSource sur PowerLinux
OpenSource sur PowerLinuxOpenSource sur PowerLinux
OpenSource sur PowerLinux
 
IBM POWER 8, une infrastructure taillée pour l'Open Source
IBM POWER 8, une infrastructure taillée pour l'Open SourceIBM POWER 8, une infrastructure taillée pour l'Open Source
IBM POWER 8, une infrastructure taillée pour l'Open Source
 
Fichier_Compétences
Fichier_CompétencesFichier_Compétences
Fichier_Compétences
 
Cours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdfCours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdf
 
Chap 1 Intro Microcontroleurs et Interruptions.pdf
Chap 1 Intro Microcontroleurs et Interruptions.pdfChap 1 Intro Microcontroleurs et Interruptions.pdf
Chap 1 Intro Microcontroleurs et Interruptions.pdf
 
ALT.Net Montréal: NETMF et Gadgeteer
ALT.Net Montréal: NETMF et GadgeteerALT.Net Montréal: NETMF et Gadgeteer
ALT.Net Montréal: NETMF et Gadgeteer
 
Projet boat loader avec le pic16F887_rapport
Projet boat loader avec le pic16F887_rapportProjet boat loader avec le pic16F887_rapport
Projet boat loader avec le pic16F887_rapport
 
Conception avec pic
Conception avec pic Conception avec pic
Conception avec pic
 
Rapport tp1 j2ee
Rapport tp1 j2eeRapport tp1 j2ee
Rapport tp1 j2ee
 
Présentation générale de l'offre de solutions TAGES
Présentation générale de l'offre de solutions TAGES Présentation générale de l'offre de solutions TAGES
Présentation générale de l'offre de solutions TAGES
 
Meetup Geneve Monitoring -TCS Performance et monitoring
Meetup Geneve Monitoring -TCS Performance et monitoringMeetup Geneve Monitoring -TCS Performance et monitoring
Meetup Geneve Monitoring -TCS Performance et monitoring
 

Cours J2ME

  • 1. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 11 Embedded JavaEmbedded Java J2MEJ2ME Tébourbi RiadhTébourbi Riadh riadh.tebourbi@supcom.rnu.tnriadh.tebourbi@supcom.rnu.tn http://www.slideshare.net/ter216/coursJ2ME
  • 2. ProgramProgram J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 22 40 Hours40 Hours 14 Hours 20-22 Mai 14 Hours 20-22 Mai 14 Hours 16-19 June 14 Hours 16-19 June 12 Hours June 23 Mai-15 June 12 Hours June 23 Mai-15 June Course Application exercises Mini project Exercises Project Project
  • 3. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 33 JavaJava platformsplatforms Java2 Standard Edition (J2SE) Java2 Standard Edition (J2SE) Java2 Enterprise Edition (J2EE) Java2 Enterprise Edition (J2EE) Java2 Micro Edition (J2ME) Java2 Micro Edition (J2ME) Java 2 Platform Applications : Standards desktop & Workstation Servers, Enterprise Applications Embedded devices Small & memory constrained devices
  • 4. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 44 JavaJava EditionsEditions - Each edition defines different sets of class libraries. Example for J2SE Java SE 7 2011 : 3 977 Java SE 6 2007 : 3 777 J2SE 5.0 2004 : 3 270 J2SE 1.4 2002 : 2 723 J2SE 1.3 2000 : 1 840 J2SE 1.2 1998 : 1 524 JDK 1.1 1997 : 477 JDK 1.0 1996 : 211  There are thousands of core J2SE runtime classes, taking up to 10-20 megabytes of space. - J2ME-based devices have fewer classes. J2ME J2SE J2EE
  • 5. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 55 What is Java 2 Micro Edition?What is Java 2 Micro Edition?  A JAVA platform for limited resources devicesA JAVA platform for limited resources devices  A subset of J2SEA subset of J2SE  Target devices:Target devices:  Mobiles phones, Smart PhonesMobiles phones, Smart Phones  PDAs, PocketPCPDAs, PocketPC  TV, VCR, CD playersTV, VCR, CD players
  • 6. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 66 Embedded devicesEmbedded devices Small & memorySmall & memory constrained devicesconstrained devices _ SmartCard _ Cellular Phone _ PocketPC _ eBook _ Digital photo device _ Set Top Box _ TV _ DVD, CD, Blu-ray player _ Game Console _ Electronic Consuming _ Payment terminal, ATM, Parking Meter _ Printer _ Car
  • 7. J2ME architectureJ2ME architecture J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 77 How to meet the requirements for a broad range of devices within target markets ? J2ME architecture defines combinations of configurations, profiles, and optional packages as elements for building complete Java runtime environments : a configuration provides the most basic set of libraries and virtual machine capabilities for a broad range of devices, a profile is a set of APIs that support a narrower range of devices an optional package is a set of specific APIs.  Each combination is optimized for the memory, processing power, and I/O capabilities of a related category of devices.
  • 8. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 88 ConfigurationsConfigurations Define the base characteristics of a runtime environment for a certain type of devices with similar set of characteristics and resources. They consist of a virtual machine and a basic set of APIs. 2 base configurations: CLDC (Connected Limited Device Configuration): to fit small mobile devices CDC (Connected Device Configuration) : target towards more capable mobile devices like smart-phones and set top boxes
  • 9. CDC & CLDCCDC & CLDC J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 99 Connected Limited Device Configuration (CLDC): - CLDC is the smaller of the two configurations. - It is designed for devices with intermittent network connections, slow processors and limited memory. Typical examples: Mobile phones Two-way pagers, PDAs, - These devices typically have either 16-bit or 32-bit CPUs, and a minimum of 128 KB to 512 KB of memory for the Java platform implementation and associated applications. - KVM as VM Connected Device Configuration (CDC): - CDC is designed for devices that have more memory, faster processors, and greater network bandwidth, such as - TV set-top boxes, residential gateways - in-vehicle telematics systems, and high-end PDAs…. - Most CDC-targeted devices have 32-bit CPUs and a minimum of 2MB of memory. - CVM as VM
  • 10. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1010 ProfilesProfiles Consist of a set of APIs for a specific device type or a specific feature. They allow the use of specific features and should be associated with a configuration. They used to provide modularity to the J2ME platform. (profile = minimum set of APIs for similar devices) Profil Configuration   MIDP 1.0  CLDC Package javax.microedition.* MIDP 2.0  CLDC Basic profile PDA CLDC PDAs that have better screens and more memory than cell phones. Mobile Media API (MMAPI) : optional package  CLDC Play audio and vidéo Wireless Messaging API (WMA): optional package  CLDC Send & receive SMS Java APIs for Bluetooth: optional package  CLDC Bluetooth Foundation Profile  CDC Include almost all of the core Java 2 Version 1.3 core libraries Personal Basis Profile CDC Adds basic user interface functionality to the Foundation Profile Personal Profile  CDC Platforms that can support a more complex user interface RMI optional package CDC Remote Method Invocation JDBC optional package  CDC  Java Database Connectivity (JDBC) API J2ME Web Services: optional package CDC Web Services Mobile 3D Graphics API for J2ME CDC 3D Game profile CDC Game app development
  • 11. Configurations, profiles & optional packagesConfigurations, profiles & optional packages J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1111 Mobile Service Architecture (MSA) JSR: Java Specification Requests  https://jcp.org/en/jsr/tech?listBy=1&listByType=platform
  • 12. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1212 ExamplesExamples Manufacturer Model Wireless Technology Frequency (MHz) Software Screen Alcatel One Touch 735i E-GSM, GSM 900, 1800 MIDP 2.0, WMA 1.0, CLDC 1.0 128x128/12 bits Motorola A388c GSM/GPRS 900, 1800, 1900 MIDP 1.0, CLDC 1.0 240x320/16 bits Motorola A760 MIDP 2.0, CLDC 1.0 320x240/16 bits Motorola T720i GSM/GPRS 1900 MIDP 1.0, CLDC 1.0 120x160/12 bits Nokia 3100 GSM/GPRS 900, 1800, 1900 MIDP 1.0, WMA 1.0, CLDC 1.0 128x128/12 bits Nokia 3200 GSM/GPRS/EDGE 900, 1800, 1900 MIDP 1.0, WMA 1.0, CLDC 1.0 128x128/12 bits Nokia 5140 GSM 900, 1800, 1900 CLDC 1.1, MIDP 2.0 128x128/12 bits Nokia 9500 GSM, GSM/GPRS 850, 900, 1800, 1900 JTWI 1.0, M3DAPI 1.0, CLDC 1.1, MIDP 2.0, MMAPI 1.1, LAPI 1.0, WMA 1.1 640x200/16 bits Nokia 7610 GSM 850, 900, 1800, 1900 MIDP 1.0, MIDP 2.0, CLDC 1.0 176x208/16 bits Samsung SGH-S100 GSM/GPRS 900, 1800, 1900 MIDP 1.0, CLDC 1.0 128x160/16 bits Siemens C55 GSM/GPRS 900, 1800 MIDP 1.0, CLDC 1.0 101x64/1 bit Siemens S6V GSM/GPRS 900, 1800, 1900 JTWI 1.0, M3DAPI 1.0, CLDC 1.1, MIDP 2.0, MMAPI 1.1, LAPI 1.0, JABWT 1.0, WMA 1.1 132x176/16 bits Sony Ericsson P908 GSM/GPRS 900, 1800, 1900 MIDP 2.0, PersonalJava 1.1.1, JABWT 1.0, CLDC 1.0, WMA 1.1 208x320/16 bits Before you can develop a mobile application you must know the configuration and profiles it can support:
  • 13. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1313 MIDP ProfileMIDP Profile (Mobile Information Device Profile)(Mobile Information Device Profile) •128KB of non-volatile memory for the MIDP implementation •32KB of volatile memory for the runtime heap •8KB of non-volatile memory for persistent data •A screen of at least 96 × 54 pixels •Some capacity for input, either by keypad, keyboard, or touch screen •Two-way network connection, possibly intermittent http://java.sun.com/products/midp/ : MIDPMIDP is for a set of devices known asis for a set of devices known as mobile information devicesmobile information devices (MIDs). Minimal characteristics of MIDs:(MIDs). Minimal characteristics of MIDs:
  • 14. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1414 MIDP ApplicationMIDP Application  MIDP does not support the running of applicationsMIDP does not support the running of applications that use a static main method as their entry point,that use a static main method as their entry point, nor calling the System.exit method in order tonor calling the System.exit method in order to terminate.terminate.  Instead, we use aInstead, we use a MIDletMIDlet, which is a MIDP, which is a MIDP application.application.
  • 15. MIDlet life cycleMIDlet life cycle J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1515 •The life-cycle defines the execution states of a MIDlet : creation, start, pause, and exit  •The application management software (AMS) is the software on a device that manages the downloading and life-cycle of MIDlets. •The AMS provides the runtime environment for a MIDlet. It enforces security, permissions, and execution states. Constructor startApp( ) pauseApp () destroyApp() destroyApp()
  • 16. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1616 MIDlet programmingMIDlet programming  A MIDP application must be a sub-class of MIDletA MIDP application must be a sub-class of MIDlet class:class: public class MyMidlet extends MIDlet {…}public class MyMidlet extends MIDlet {…}  Equivalent MIDP of an applet, where the executionEquivalent MIDP of an applet, where the execution and the stop are controlled by theand the stop are controlled by the applicationapplication management softwaremanagement software  When a MIDlet is executed the AMS calls ltheWhen a MIDlet is executed the AMS calls lthe method MIDlet.startApp() after the constructormethod MIDlet.startApp() after the constructor
  • 17. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1717 Architecture of a MIDletArchitecture of a MIDlet public class MyMidlet extends MIDlet { public MyMidlet() { //the constructor } public void startApp() { // MyMidlet it starts here (after the constructor) } public void pauseApp() { // MyMidlet is now in “pause” mode (no display) } public void destroyApp(boolean unconditional) { // MyMidlet is destroyed, clean if necessary } }
  • 18. UI Programming ModelUI Programming Model J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1818  The central abstraction is a screen  Only one screen may be visible at a time  Three types of screens:  Predefined screens with complex UI components (List, TextBox)  Generic screens (Form where you can add text, images, etc)  Screens used with low-level API (Canvas)  The Display class is the display manager  It is instantiated for each active MIDlet  Provides methods to retrieve information about the device’s display capabilities.
  • 19. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 1919 APIAPI UI Programming ModelUI Programming Model ScreenCanvas Form TextBoxListBox ItemAlert ChoiceGroup DateField Gauge ImageItem StringItem TextField Displayable Low level API (game) High level API (GUI)
  • 20. DisplayDisplay J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2020 Display manages device’s screen  Use getDisplay() (static method of Display) to access the display - in the startApp() method for example  Use the returned Display object to determine device capabilities or current displayable  isColor()  color or grayscale device  numColors()  number of colors supported  numAlphaLevels()  number of transparency level  getCurrent()  a reference to what (displayable) currently being shown  After creating something to show as an instance of Displayable you can display it:  setCurrent(Displayable next)  setCurrent(Alert alert, Displayable nextDisplayable)
  • 21. Librairies de base de MIDPLibrairies de base de MIDP J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2121  Interface utilisateurInterface utilisateur  javax.microedition.lcduijavax.microedition.lcdui L’environnement de base d’interface utilisateur.L’environnement de base d’interface utilisateur.  javax.microedition.lcdui.gamejavax.microedition.lcdui.game Facilite le développement de jeux sur mobile.Facilite le développement de jeux sur mobile.  PersistencePersistence  javax.microedition.rmsjavax.microedition.rms Un mécanisme simple et sécurisé de persistence.Un mécanisme simple et sécurisé de persistence.  Application Lifecycle PackageApplication Lifecycle Package  javax.microedition.midletjavax.microedition.midlet Définit l’interaction entre l’application est l’environnementDéfinit l’interaction entre l’application est l’environnement  RéseauRéseau  javax.microedition.iojavax.microedition.io La gestion des connexions.La gestion des connexions.  AudioAudio  javax.microedition.mediajavax.microedition.media Les outils de base pour créer un player.Les outils de base pour créer un player.  javax.microedition.media.controljavax.microedition.media.control La commande du player.La commande du player.  Public KeyPublic Key  javax.microedition.pkijavax.microedition.pki Gestion des certificats utilisés en connexion sécurisée.Gestion des certificats utilisés en connexion sécurisée.  Core PackagesCore Packages  java.iojava.io Gestion des entrées sorties au travers des DataStreams..Gestion des entrées sorties au travers des DataStreams..  java.langjava.lang Les classes de base de Java.Les classes de base de Java.  java.utiljava.util les collection classes, la date et le temps..les collection classes, la date et le temps..
  • 22. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2222 1/2 Un premier Exemple HelloSupcomMIDlet.java
  • 23. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2323 2/2
  • 24. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2424  Afficher un texte qui défile: utilisation de la classe Ticker: HelloSupcomMIDletbis.java …..Pour la Suite voir HelloSupcomMIDlet
  • 25. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2525 Un deuxième Exemple 1/2 SimpleListe1.java
  • 26. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2626 2/2
  • 27. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2727 list = new List("Sample list", List.IMPLICITList.IMPLICIT, …); Remarque sur le constructeur de la classe List: new List(String title, int listTypeint listType, …) list = new List("Sample list", List.EXCLUSIVEList.EXCLUSIVE, …); list = new List("Sample list", List.MULTIPLEList.MULTIPLE, …); (SimpleListe1.java) (SimpleListe2.java) (SimpleListe3.java)
  • 28. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2828 Action après choix dans une liste: troisième Exemple: SimpleListe4.java 1/2
  • 29. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 2929 2/2
  • 30. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3030 Forms et ItemsForms et Items  Form (class) est le seul "container" dans MIDPForm (class) est le seul "container" dans MIDP  Form contient des objets Item (class) (doc API:Form contient des objets Item (class) (doc API: A superclass forA superclass for components that can be added to a Formcomponents that can be added to a Form))  Les éléments sont ajoutés en utilisant Form.append()Les éléments sont ajoutés en utilisant Form.append()  form.append(item);form.append(item);  form.append("string");form.append("string");  Quand un Item change d’état (suite à une action sur celui-ci), ilQuand un Item change d’état (suite à une action sur celui-ci), il génère l’événement ItemStateChangedgénère l’événement ItemStateChanged  Capté par un ItemStateListener définit sur la FormCapté par un ItemStateListener définit sur la Form  Le changement d’état appelle la méthode ItemStateListenerLe changement d’état appelle la méthode ItemStateListener
  • 31. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3131 Diagramme des ItemsDiagramme des Items • 1 Form peut avoir plusieurs Items (components)
  • 32. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3232 Example 4 (1/2)Example 4 (1/2) Form1.javaForm1.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Form1 extends MIDlet implements ItemStateListener { protected Display display; protected Form form; public Form1() { display = Display.getDisplay(this); form = new Form("Info entry form"); form.append(new TextField("Name", "", 10, TextField.ANY)); form.append(new Gauge("Age (0-100)", true, 10, 2)); form.append(new ChoiceGroup("Job", Choice.EXCLUSIVE, new String[] {“active", "student"}, null)); form.setItemStateListener(this); }
  • 33. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3333 Example 4 (2/2)Example 4 (2/2) public void itemStateChanged(Item item) { // if an item changes – it gets sent here! System.out.println("State changed on item " + item.toString()); } public void startApp() { display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { display = null; form = null; } }
  • 34. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3434 Image et ImageItemImage et ImageItem •Classes pour manipuler des images •Image: classe pour créer un objet image et contient des attributs tels que Hauteur Largeur de l’image. •ImageItem: sert pour afficher l’image sur une Form. Elle définit comment l’image va être afficher à l’écran (à gauche, centrée, taille, etc..) •MIDP offre deux types d’images: • immutable: ne peut pas être modifiée après création (une image lue d’un fichier image par exemple) •mutable : une image créée et stockée en mémoire par l’utilisateur.
  • 35. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3535 Affichage d’une imageAffichage d’une image ImageItem(String label, Image img, int layout, String altText) Constructeurs:Constructeurs: Image createImage(String name) Form fmMain = new Form("Images"); ... // Create an image Image img = Image.createImage("/supcom.png"); // Append to a form fmMain.append(new ImageItem(null, img, ImageItem.LAYOUT_CENTER, null)); Affichage sur une Form:Affichage sur une Form:
  • 36. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3636 Exemple 5 (1/2)Exemple 5 (1/2) HelloSupcomMIDletfin.javaHelloSupcomMIDletfin.java
  • 37. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3737 Exemple 5 (2/2)Exemple 5 (2/2)
  • 38. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3838 Les ThreadsLes Threads •Utilisés pour faire du multitâche: Pendant la lecture d’une vidéo, l’interface graphique d’une application est fonctionnelle Lors d’une animation ont peut écouter la musique. •Thread = unité d'exécution faisant partie d'un programme. Cette unité fonctionne de façon autonome et parallèlement à d'autres Threads. chaque unité se voit attribuer des intervalles de temps au cours desquels elles ont le droit d'utiliser le processeur pour accomplir leurs traitements •Un programme (ou partie d’un programme) java peut être mis sous un Thread. •Le principal avantage des Threads est de pouvoir répartir différents traitements d'un même programme en plusieurs unités distinctes pour permettre leur exécution "simultanée". •La classe java.lang.Thread et l'interface java.lang.Runnable sont les bases pour le développement des Threads en java. Par exemple, pour exécuter des Midlets dans un thread, il faut que celles ci implémentent l'interface Runnable.
  • 39. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 3939 Les ThreadsLes Threads 1) public class MaMidlet extends MIDlet implements CommandListener, Runnable {….} Création d’un Thread dans une Midlet 2) public Thread(Runnable target) //Allocates a new Thread object with a specific target object whose run method is called. //Créer un objet Thread pour un autre objet “target” (une Midlet par exemple) et c’est la //methode run() de “target” qui sera exécutée. Thread t = new Thread(this) t.start(); apple de la méthode surchargée run(); 3) //implementation de la méthode run() de la Midlet: public void run() { …..//faire un traitement long }
  • 40. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4040 Les ThreadsLes Threads Création d’un Thread pour une méthode Une méthode d’une Midlet peut être mise sous un Thread indépendant. Elle sera exécuter alors en parallèle avec la Midlet. private void doSomethingBig() { new Thread() { public void run() { …….//do something big } }.start(); }
  • 41. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4141 MIDP 2.0MIDP 2.0 Quoi de neuf ? (disponible été 2003) • UI •Multimédia :Mobile Media API (MMAPI) •Amélioration des formulaire •Images RGB • Game API javax.microedition.lcdui.game GameCanvas, LayerManager, Layer, TiledLayer, Sprit
  • 42. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4242 MIDP 2.0MIDP 2.0 • Sécurité • HTTPS • PKI (Certificats) • JAR signé La signature et la clé publique sont ajoutés au JAD • Permissions Nouvelles entrées du JAD : MIDIet-Permissions, MIDIet-Permissions-Op • Lancement Push de MIDLet sur des demandes entrantes de connexions réseaux • L'entrée MIDlet-Push-<n> du JAD précise: l’URL local de connection URL la classe de la MIDLet l’adresse IP de la machine autorisée à lancer un push • Exemple : MIDIet-Push-1: socket://:76, exemple.PushLet. 192.161.60
  • 43. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4343 MessagingMessaging • Wireless Messaging API (WMA) pour J2ME Messageries pour « pager » et téléphone mobile • WMA 1.1 (JSR 120) permet l’envoie et la réception de SMS (Short Message Service) ou de CBS (Cell Broadcast Service) • WMA 2.0 (JSR 205) prend en compte l’envoies MMS
  • 44. Wireless Messaging API (WMAWireless Messaging API (WMA 2.0)2.0) J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4444 Message: classe de base pour définir un message. C’est une superclasse pour des types de messages BinaryMessage (fichier wav par exemple), MultipartMessage (message en plusieurs parties) et textMessage (message texte). MessageConnection: fournie les fonctionnalités de base pour créer, envoyer et recevoir les messages. package, javax.wireless.messaging
  • 45. Wireless Messaging API (WMAWireless Messaging API (WMA 2.0)2.0) J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4545 MessageListener: Interface pour définir un “listener” et permet d’implémenter des notifications asynchrones des messages reçus MessagePart: permet de définir une partie a ajouter à un message ayant plusieurs parties (MultipartMessage).  smsExemple.java
  • 46. Record Management StoreRecord Management Store J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4646 API qui permettent aux applications MIDP la persistance sur les appareils. Record Management System (RMS), un espace mémoire pour les MIDlets Record Store: RS - Fichiers binaires dépendants de la plateforme car ils sont créés dans des répertoires dépendants de la plateforme - une collection d’enregistrements avec un clé primaire unique (integer) - L’ ID d’un enregistrement du premier enregistrement = 1 un compteur incrémenté de 1 à chaque création d’un enregistrement. javax.microedition.rms
  • 47. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4747 MultimédiaMultimédia •Mobile Media API (MMIA) •Son,MIDI, Vidéo, streaming… •En remplacement de JMF (trop gros 650k, awt) •Compact: 150K (MIDI, MPEG1, MP3,…) MIME Type Description audio/midi MIDI files audio/sp-midi Scalable Polyphony MIDI audio/x-tone-seq MIDP 2.0 tone sequence audio/x-wav WAV PCM sampled audio image/gif GIF 89a (animated GIF) video/mpeg MPEG video video/vnd.sun.rgb565 Video capture
  • 48. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4848 Mobile Media API (MMIA) Introduction Spécificités: •Support pour “Génération de tonalité”, “Playback”, et “enregistrement/capture multimédia”: l’API accepte tout contenu audio et vidéo. •Tien compte des contraintes de mémoire sur des plateformes CLDC •Extensible: Nouvelles fonctionnalités peuvent être rajoutées; d’autres formats de contenu audio, vidéo peuvent être supportés.
  • 49. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 4949 Gestion/Traitement du contenu Deux parties: •Gestion du protocole (Protocol Handling): Lire les données d’une source, exemple: fichier, serveur(réseau), streaming. •Gestion du contenu(Content Handling): une fois lu, le contenu est décodé et restitué via une sortie du périphérique (haut parleur pour le son, écran pour la vidéo)  Trois classes: •Player: Lit les données d’une source, les traites et les restitue. •Manager: Pour créer des players, jouer des tonalités, contient les protocoles et les types de contenus que le mobile supporte. •DataSource: Définit comment des données d’une source (fichier, http, rtp) sont lues. On peut créer un nouveau DataSource (pour un nouveau format par exemple)
  • 50. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5050 ManagerManager C’est la classe centrale pour creéer des “players” et offre trois methodes pour indiquer la source de données: createPlayer(DataSource source) createPlayer(InputStream stream, String type) createPlayer(String locator)createPlayer(String locator) Player p = Manager.createPlayer("capture://video"); Player p = Manager.createPlayer ("http://nokia.com/chanson.mp3"); Player p = Manager.createPlayer("http://movies.com/film.mpg"); Type Media Exemple syntaxe Capture audio "capture://audio" : capture audio sur périph défaut. "capture://devmic0?encoding=pcm" capture audio sur devmic0 avec encodage PCM. Capture vidéo "capture://video" : capture video à partir du périphérique de capture par défaut "capture://devcam0?encoding=rgb888&width=100&height=50" : capture d’une camera, rgb888 mode encodage, avec “width” “height” (taille) spécifiques Radio "capture://radio?f=105.1&st=stereo " : tuner à la fréquence 105.1 FM mode stéréo. Streaming vidéo/audio/texte d’une source externe "rtp://host:port/type" : type = audio, vidéo ou texte Jouer des tonalités/ MIDI "device://tone" :player pou jouer des tonalités "device://midi" :ou MIDI
  • 51. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5151 PlayerPlayer •Créé avec Manager •Permet de restituer un contenu multi-media •Possède des états: UNREALIZED, REALIZED, PREFETCHED, STARTED, et CLOSED UNREALIZED: état initial, juste après création REALIZED: initialise les infos sur les medias (type, périphériques de captures, etc). PREFETCHED: établis la connexions avec la média et la charge, établit les connections réseau pour le streaming. STARTED: la lecture a commencé (mode lecture) CLOSED: arrêt de lecture, arrêt du lecteur •realize() •prefetch() •start() •stop() •deallocate() •close() Passage d’un état à un autre:
  • 52. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5252 Player(2)Player(2) •On associe à un lecteur un contrôle (control) : une fonctionnalité média spécifique. •Examples: VideoControl: obtient et contrôle la fenêtre vidéo MIDIControl, ToneControl: accès aux propriétés MIDI/Tonalités du périphérique. VolumeControl: contrôle du volume Player p; Form frm; vc = (VideoControl)p.getControl("VideoControl"); volc = (VolumeControl)p.getControl("VolumeControl"); frm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null)); //Ajout de la fenêtre vidéo sur une forme en tant que Item. volc.setLevel(50); //Volume à 50 (entre 0 et 100) •Usage:
  • 53. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5353 Exemple 1 (1/2)Exemple 1 (1/2) VideoPlayer.javaVideoPlayer.java Lecture d’un fichier vidéo stocké sur un serveur (exmple apache Tomcat). Url: http://localhost/midp/shark. mpg
  • 54. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5454 Exemple 6 (2/2)Exemple 6 (2/2)
  • 55. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5555 Exemple 7 (1/2)Exemple 7 (1/2) VideoPlayer1.javaVideoPlayer1.java ….. ….. Lecture d’un fichier vidéo à partir de l’archive jar. Utilisation de Manager. createPlayer(InputStream stream, String type) L’InputStream est obtenu à partir de l’objet application obtenu par getClass()
  • 56. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5656 Snapshot (capture d’une image)Snapshot (capture d’une image) Vidéo lue  capturer une image byte[] getSnapshot(java.lang.String imageType) Méthode getSnaphot sur un objet VideoControl snapshot = vc.getSnapshot("encoding=jpeg"); VideoControl vc; byte[] snapshot; ImageItem imi; Image im = Image.createImage(snapshot, 0, snapshot.length);  On obtient un objet Image qu’on peut afficher à l’aide d’un ImageItem (voir exemple 5) Exemple:
  • 57. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5757 ApplicationApplication EN TP: MIDlet qui lit une vidéo depuis un URL dans une liste Fonctions Play, Pause et Stop (utilisation d'un thread pour play) Fonction Snapshot (produire une image à partir de la vidéo) (un autre thread) Fonction contrôle volume (utilisation de Gauge) Fonction partage URL avec un ami par SMS Fonction sauvegarder/charger les URLs dans la mémoire du mobile (RMS) VideoPlayer2.javaVideoPlayer2.java VideoPlayer3.javaVideoPlayer3.java
  • 58. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5858 DéploiementDéploiement Une Midlet java peut être déployée sur un périphérique mobile: 1) Directement par liaison USB, Série, Blutooth.. entre un PC et le Mobile • Utilisation d’un logiciel de téléchargement (Oxygène phone manager, NOKIA phone manager,..) 2) OTA: Over The Air: Téléchargement à partir d’un serveur. • Utilisation d’un URL = adresse de la Midlet (Acces à travers le réseau), exemple: http//nokia.com •Sur le mobile: le « Application ManagerApplication Manager » gère l’installation, mise à jour, désinstallation et exécution des applications java (un mini SE) Dans les deux cas : il faut créer un package d’installation .jar (archive) {.class , images, fichiers etc..} et .jad (description))
  • 59. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 5959 ExempleExemple MIDlet-1: HelloSupcomMIDletfin, , HelloSupcomMIDletfin MIDlet-Jar-Size: 66756 MIDlet-Jar-URL: http://localhost:8080/midp/hello1.jar MIDlet-Name: hello1 MIDlet-Vendor: Tebourbi Riadh MIDlet-Version: 1.0 MicroEdition-Configuration: CLDC-1.0 MicroEdition-Profile: MIDP-2.0 hello1.jad (En locale copier hello1.jar et hello1.jad sur le mobile (par liaison USB, Blutooth etc..) et exécuter hello1. )
  • 60. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6060 Exemple OTA(1)Exemple OTA(1) Sur le SERVEUR URL: http://ip_serveur/midp/hello1.html <html> <head> <title>hello1</title> </head> <body> <a href="http://localhost:8080/midp/hello1.jad">hello1.jad</a> </body> </html> Hello1.html •Copier les fichiers .jar et .jad dans le répertoire des applications WEB •Écrire hello1.html qui contient un lien vers hello1.jad •Exemple de serveur: Tomcat
  • 61. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6161 Exemple OTA(2)Exemple OTA(2) Sur le Mobile 1 2 3 4 5 6 7 8
  • 62. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6262 Outils de développementOutils de développement  Quelques outils:Quelques outils:  J2ME Wireless Toolkit 2.0.1J2ME Wireless Toolkit 2.0.1  Sun ONE Studio Mobile Edition 5Sun ONE Studio Mobile Edition 5  CodeWarrior Wireless Studio 7.0CodeWarrior Wireless Studio 7.0  Nokia Developer’s Suite Beta J2MENokia Developer’s Suite Beta J2ME  RIM BlackBerry JDE 3.2RIM BlackBerry JDE 3.2  Motorola LWT1.0Motorola LWT1.0
  • 63. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6363 Sun ONE Studio Mobile EditionSun ONE Studio Mobile Edition
  • 64. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6464 BlackBerry Java DevelopmentBlackBerry Java Development EnvironmentEnvironment
  • 65. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6565 Nokia Developer’s Suite &Nokia Developer’s Suite & CodeWarriorCodeWarrior
  • 66. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6666 J2ME Wireless ToolkitJ2ME Wireless Toolkit
  • 67. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6767 InstallationInstallation j2me_wireless_toolkit-2_2-windows.exe. Installation dans c:/wtk22 Applications Midlets .jar, .jad Midlet hello1 Les .class Ressources de l’application: exemple: supcom_rgb.png Codes sources, exemple: HelloSupcomMIDletfin.java
  • 68. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6868 Création d’une Midlet(1)Création d’une Midlet(1) « DémarrerprogrammesJ2ME Wireless Toolkit 2.2KToolbar » NewProject: hello « Settings » Nom Nom classe (fichier .java)
  • 69. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 6969 Création d’une Midlet(1)Création d’une Midlet(1) Nous allons tester la Midlet « HelloSupcomMIDlet » (exemple 1)  Le répertoire C:WTK22appshellosrc doit contenir le fichier HelloSupcomMIDlet.java Ecrire le fichier HelloSupcomMIDlet.java (à l’aide d’un éditeur de texte, ou KAWA). Le copier dans le répertoire C:WTK22appshellosrc Compiler: « ProjectBuild » Exécuter: « ProjectRun »: exécution sur l’émulateur JAR: « Projectpackagecreate package »: création du .jar
  • 70. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 7070 Création d’une deuxième MidletCréation d’une deuxième Midlet Nous allons rajouter au projet hello une deuxième midlet: HelloSupcomMIDletbis Ecrire le fichier HelloSupcomMIDletbis.java (à l’aide d’un éditeur de texte, ou KAWA). Le copier dans le répertoire C:WTK22appshellosrc Dans « Settings »  « Midlets »  « Add » entrer le nom de la midlet et la nom de la classe (HelloSupcomMIDletbis)  « OK » Build + RUN  Exécution avec choix Midlet à exécuter
  • 71. J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 7171 A VOUS DE JOUERA VOUS DE JOUER