This MIDlet suite includes two MIDlets, TextHandler
and AudioHandler
.
Of these two MIDlets, the deceptively named TextHandler
functions
as the main MIDlet that can display text content or launch AudioHandler
when
audio content needs to be invoked.
These MIDlets deal with the following use cases:
Handle text content in the same MIDlet
TextHandler
MIDlet handles the content type text/plain
.
When such a file is requested by the MIDlet, the text is displayed right away
using the TextViewer
class in the MIDlet.
Invoke audio content in another MIDlet
TextHandler
does not have the ability to handle
audio content, but it is set to invoke the AudioHandler
MIDlet,
when audio/x-wav
content type is requested. The AudioHandler
is
then launched and it handles the audio content.
Invoke native content handlers
Apart from text/plain
and audio/x-wav
,
this MIDlet suite does not include handlers for any additional content. So
when an image file is requested in this MIDlet, the MIDlet invokes the native
handler for that content type.
Each one of these use cases is demonstrated by an example. When the TextHandler
MIDlet
starts, there is a menu that contains three choices, each an example of one
use case. The MIDlet works as described in the list above; the text is displayed
in the same MIDlet, the audio is played in the invoked AudioHandler
instance,
and the native handler is used for the image file.
These content type registration is defined in the JAD file, a portion
of which is shown below. Notice the MicroEdition-Handler-#
parameter
that contains the classname of the MIDlet and the content type that the MIDlet
is registered to handle. Another important parameter is Nok-Resource-File-Name
,
which is a custom JAD attribute and defined in ChoiceList
class.
This parameter contains a link to a text file, links.txt
,
which in turn contains the links to the content that is displayed in the main
menu.
Another MIDlet, AudioHandler
, is registered dynamically
in the
MIDlet-Permissions: javax.microedition.io.Connector.http,javax.microedition.content.ContentHandler MIDlet-1: Text Handler,/com/nokia/midp/example/jsr211/res/icon.png,com.nokia.midp.example.jsr211.texthandler.TextHandler MicroEdition-Handler-1: com.nokia.midp.example.jsr211.texthandler.TextHandler,text/plain MicroEdition-Handler-1-ID: com.nokia.midp.example.jsr211.texthandler.TextHandler Nok-Resource-File-Name: /com/nokia/midp/example/jsr211/res/links.txt
The links.txt
file is located in the res
directory.
It contains the following rows:
ReadMe - txt Help.txt (http)~http://localhost/ReadMe.txt Audio - wav cock.wav (http)~http://localhost/cock.wav Image - img nokia.png (http)~http://localhost/nokia.png
The line preceded by the ~
sign is the text shown
to the user in the main menu and the URL after that the link to the actual
file. In this example, the files are retrieved from the root of local web
server. The server is configured on the same computer as the emulator that
runs this example. If you place the files on an external web server, or use
your own customized files, you need to edit this file accordingly.