Upload
tebourbi-riadh
View
24.983
Download
0
Embed Size (px)
DESCRIPTION
J2ME
Citation preview
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 11
Embedded JavaEmbedded JavaJ2MEJ2ME
Tébourbi RiadhTébourbi [email protected]@supcom.rnu.tn
http://www.slideshare.net/ter216/coursJ2ME
ProgramProgram
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 22
40 Hours40 Hours
14 Hours20-22 Mai14 Hours20-22 Mai
14 Hours16-19 June14 Hours
16-19 June12 Hours
June 23 Mai-15 June12 Hours
June 23 Mai-15 June
CourseApplication exercisesMini project
ExercisesProject
Project
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 33
Java Java 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
Java Java EditionsEditions- Each edition defines different sets of class libraries.
Example for J2SEJava SE 7 2011 : 3 977Java SE 6 2007 : 3 777J2SE 5.0 2004 : 3 270J2SE 1.4 2002 : 2 723J2SE 1.3 2000 : 1 840J2SE 1.2 1998 : 1 524JDK 1.1 1997 : 477JDK 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 A JAVA platform for limited resources devicesdevices
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 & Small & memory constrained devicesmemory constrained 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'COM J2ME, Tebourbi Riadh, SUP'COM 88
Configurations Configurations
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 phonesTwo-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'COM J2ME, Tebourbi Riadh, SUP'COM 1010
Profiles Profiles 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 CLDCPDAs 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 Configurations, profiles & optional packagespackages
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 ModelWireless
TechnologyFrequency
(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'COM J2ME, Tebourbi Riadh, SUP'COM 1313
MIDP Profile MIDP Profile (Mobile Information Device (Mobile Information Device
Profile)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 as is for a set of devices known as mobile information mobile information devicesdevices (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 MIDP does not support the running of applications that use a static main method as applications that use a static main method as their entry point, nor calling the System.exit their entry point, nor calling the System.exit method in order to terminate. method in order to terminate.
Instead, we use a Instead, 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 A MIDP application must be a sub-class of MIDlet class:MIDlet class:
public class MyMidlet extends MIDlet {…}public class MyMidlet extends MIDlet {…}
Equivalent MIDP of an applet, where the Equivalent MIDP of an applet, where the execution and the stop are controlled by the execution and the stop are controlled by the application management software application management software
When a MIDlet is executed the AMS calls lthe When a MIDlet is executed the AMS calls lthe method MIDlet.startApp() after the constructor method 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 UIcomponents (List, TextBox) Generic screens (Form where you can addtext, 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
API API 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’environnement Dé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.media javax.microedition.media Les outils de base pour créer un player.Les outils de base pour créer un player.
javax.microedition.media.control javax.microedition.media.control La commande du player.La commande du player.
Public KeyPublic Key javax.microedition.pki javax.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/2Un premier ExempleHelloSupcomMIDlet.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/2SimpleListe1.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 MIDP Form (class) est le seul "container" dans MIDP Form contient des objets Item (class) (doc API: Form contient des objets Item (class) (doc API: A A
superclass for components that can be added to a Formsuperclass for components 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 Quand un Item change d’état (suite à une action sur celui-ci), il génère l’événement ItemStateChangedcelui-ci), il génère l’événement ItemStateChanged Capté par un ItemStateListener définit sur la Form Capté 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 imageImage img = Image.createImage("/supcom.png");// Append to a formfmMain.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 ThreadsCré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 APIjavax.microedition.lcdui.gameGameCanvas, 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 URLla classe de la MIDLetl’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 (WMA Wireless 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 (WMA Wireless 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 enregistrementdu premier enregistrement = 1un 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 Snapshot (capture d’une image)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
ApplicationApplicationEN 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éploiementUne 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, , HelloSupcomMIDletfinMIDlet-Jar-Size: 66756MIDlet-Jar-URL: http://localhost:8080/midp/hello1.jarMIDlet-Name: hello1MIDlet-Vendor: Tebourbi RiadhMIDlet-Version: 1.0MicroEdition-Configuration: CLDC-1.0MicroEdition-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 Development BlackBerry 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
InstallationInstallationj2me_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émarrerprogrammesJ2ME Wireless Toolkit 2.2KToolbar »
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:\WTK22\apps\hello\src 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:\WTK22\apps\hello\src
Compiler: « ProjectBuild »
Exécuter: « ProjectRun »: exécution sur l’émulateur
JAR: « Projectpackagecreate package »: création du .jar
J2ME, Tebourbi Riadh, SUP'COMJ2ME, Tebourbi Riadh, SUP'COM 7070
Création d’une deuxième Création d’une deuxième MidletMidlet
Nous allons rajouter au projet hello une deuxième midlet: HelloSupcomMIDletbisEcrire le fichier HelloSupcomMIDletbis.java (à l’aide d’un éditeur de texte, ou KAWA). Le copier dans le répertoire C:\WTK22\apps\hello\src
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