Our Country Sites: Argentina|Brazil|Chile|Mexico|Peru

Java ME APIs deprecated in Motorola i876

Printer-friendly versionPrinter-friendly versionSend by emailSend by email

The new Motorola i876 includes a number of changes to the Java ME environment This includes the deprecation of some Motorola OEM APIs that were deprecated because there are suitable JSRs to replace them, or because their functionality was otherwise redundant or obsolete.

The deprecated APIs, and the APIs that should be used in their place on the i876 are the following:

Deprecated API Substitute API
MidiPlayer API JSR 135 - Mobile Media API
VoiceNotes JSR 135 - Mobile Media API
Crypto API JSR 77 - Security and Trust Services API (SATSA)
Lightweight Windowing Toolkit (LWT) No replacement
Math CLDC 1.1
3D API JSR 184 - Mobile 3d Graphics API for J2ME
File I/O JSR 75 - PDA Optional Packages for the J2ME Platform
DateBook API JSR 75 - PDA Optional Packages for the J2ME Platform
PhoneBook API JSR 75 - PDA Optional Packages for the J2ME Platform

If your existing applications use any of these APIs, it will be necessary to make some modifications to your code. We offer you some recommendations on how to adapt your applications so that they operate correctly.

MidiPlayer API

The package com.motorola.midi was completamente eliminated, and is replaced by JSR 135 Mobile Media API, which is now the standard for multimedia operations in Java ME including generation of MIDI sequences. JSR 135 allows for greater code portability, and allows for the use of the same code to play back audio in MIDI, WAV and MP3 formats, with greater functionality.

VoiceNotes API

O pacote com.mot.iden.voicenote foi completamente eliminado e é substituído pelo JSR 135 Mobile Media API, que é o padrão para multimídia no Java ME. O JSR 135 permite maior portabilidade do código a diferentes aparelhos, e a utilização do mesmo código para registrar áudio em vários formatos.

The com.mot.iden.voicenote was completely eliminated and is replaced by JSR 135 Mobile Media API. This allows the use of the same code base to record audio in various formats.

To record audio files with JSR 135 in the same VSELP, AMBE or AMR file formats used by the VoiceNotes API, it's only necessary to pass in the URI file:///./name.vnf in the parameter passed in to Player.createPlayer(). It makes it possible to store a file in Voice Notes format, which by default is recorded as an AMBE file with a 2400 bitrate.

Crypto API

O pacote com.motorola.iden.crypto foi completamente eliminado e é substituído pelo JSR 177 - Security and Trust Services API (SATSA). SATSA é o padrão em MIDP para o manejo de criptografia, e oferece uma interface muito mais poderosa da que oferece o Crypto API para administrar criptografia, segurança, assinaturas digitais, e outros.

The com.motorola.iden.crypto was completely eliminated and replaced by JSR 177 - Security and Trust Services API (SATSA). SATSA is the MIDP standard for cryptography, and offers a much more powerful interface to the Crypto API to administer encryption, security, digital signatures, and others.

Lightweight Windowing Toolkit (LWT)

The Lightweight Windowing Toolkit (LWT) was added to offer some easier-to-use GUI functions in MIDP 1.0 devices. That functionality was made obsolete by MIDP 2.0's functionality for form and Canvas creation, and is therefore deprecated.

Math API

The com.mot.iden.math was included in the first MIDP 1.0 devices to permit floating point calculations. CLDC 1.1 included java.lang.Float by default, and therefore the OEM class was made redundant. Therefore, it is deprecated starting with the i876.

3D API

O pacote com.motorola.iden.micro3d é desaprovado e é substituído pelo JSR 184 Mobile 3D Graphics API. Este API é disponível em todos os aparelhos iDEN com écran grande (176x220), e nos aparelhos i290 e i335.

The com.motorola.iden.micro3d package is deprecated and is substituted with JSR 184 Mobile 3D Graphics API. This API is available on all iDEN devices with a large screen (176x220), as well as on i290 and i335 devices.

File I/O

O cambio do File I/O ao uso de JSR 75 é o de mais impacto, porque afeita a todos os aplicativos que guardam dados no aparelho usando arquivos (em vez de RMS) e que se desenvolveram para os primeiros aparelhos iDEN com Java ME.

The deprecation o File I/O to the use of JSR 75 is probably the one with the largest impact, because it affects any applications that were designed for early Motorola iDEN MIDP 1.0 and MIDP 2.0 devices with square screens, as well as any other applications targeted for devices that support JSR 75 but also included the File I/O API.

Any applications that store data using File I/O rather than RMS are affected.

The modifications for supporting PIM are very straightforward, as it involves only adding two characters to the File URI:

Old Method antigo:

//to save a file to memory
(StreamConnection) Connector.open("file://filename");

//to save a file to memory with password
(StreamConnection) Connector.open("sfile://archivo;PASSWORD=1234");

New Method:

//to save a file to memory
(FileConnection) Connector.open("file:///./filename");

//to save a file to memory with a password
(FileConnection) Connector.open("sfile:///./filename;PASSWORD=1234);

//to save a file to an SD card
(FileConnection) Connector.open("file:///Storage Card/filename");

//to save a file to an SD card with a password
(FileConnection) Connector.open("sfile:///Storage Card/filename;PASSWORD=1234");

DateBook e PhoneBook API

O pacote com.motorola.iden.udm.* foi completamente eliminado e é substituído pelo JSR 75 PIM API, o que permite maior portabilidade do código a diferentes aparelhos.

The com.motorola.iden.udm.* package is deprecated and replaced by JSR 75 PIM API, which allows for greater code portability. This requires any applications that rely on this package for access to calendar and phone book items to be rewritten.

Old method for accessing PIM data:

try
        {
            /* Open a calendar in Read-Write mode. */
            calendars = UDM.openDateBook(UDM.READ_WRITE);
            Enumeration e;  
            for ( e = calendars.elements(); e.hasMoreElements(); )
            {
                dateEvent = (DateBookEvent)e.nextElement();  
                int[] type;
                type = dateEvent.getFields();
 
                /* Obtain event details. */
                StringItem userName = new StringItem("Topic",  
                    dateEvent.getString(DateBookEvent.SUMMARY));
                        }
                         /* Create an event */
                        long currentTime = 0;
                        dateEvent = calendars.createDateBookEvent();
                        dateEvent.setString(DateBookEvent.SUMMARY,  
                                "Evento");
                        currentTime = System.currentTimeMillis()+ 60*60000;
                        dateEvent.setDate(DateBookEvent.START, currentTime);
                        dateEvent.setDate(DateBookEvent.END,  currentTime + 600000);                   
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

New method using JSR 75 PIM API:

  try {
          /* Open a calendar in Read-Write mode. */
   
        EventList listaDeEventos =
                (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
       
        Enumeration e = listaDeEventos.items();
       
        // Read all fields of the event, and add a summary field if it is supported
                while (e.hasMoreElements() );
                {
                        Event evento = (Event)e.nextElement();
                        campos[] = evento.getFields()
                        StringBuffer valores = new StringBuffer();
                        for (int numeroCampo = 0; numeroCampo < campos.length; numeroCampo++) {
                                int dataType = listaDeEventos.getFieldDataType(campos[numeroCampo]); //review the type of data that this field supports
                                int numIndices = listaDeEventos.countValues(campos[numeroCampo]); //each field can contain more than one value, represented by an index.
                                if (dataType == PIMItem.STRING) //in case the field contains text
                                {      
                                  for (int indice=0; indice < numIndices; indice++) {
                                         valores.append(evento.getFieldLabel(campos[numeroCampo])).append(" ").append(numeroCampo).append(": ").append(evento.getString(campos[numeroCampo], indice);
                                     }
                                }
                                else if (dataType == PIMItem.DATE) //in case the field contains a date
                                {
                                  for (int indice=0; indice < numIndices; indice++) {  
                                     Date fecha = new Date(evento.getDate(campos[numeroCampo], indice));
                                         valores.append(evento.getFieldLabel(campos[numeroCampo])).append(" ").append(numeroCampo).append(": ").append(fecha);
                                     }                         
                                }
                                else if (dataType == PIMItem.INT) //in case the field contains a numerical value
                                {
                                  for (int indice=0; indice < numIndices; indice++) {  
                                         valores.append(evento.getFieldLabel(campos[numeroCampo])).append(" ").append(numeroCampo).append(": ").append(evento.getInt(campos[numeroCampo], indice);
                                     }                         
                                }
                                else if (dataType == PIMItem.BOOLEAN) //in case the field contains a boolean
                                {
                                  for (int indice=0; indice < numIndices; indice++) {  
                                         valores.append(evento.getFieldLabel(campos[numeroCampo])).append(" ").append(numeroCampo).append(": ").append(evento.getBoolean(campos[numeroCampo], indice);
                                     }                         
                                }
               
                                //modify the first index value of the Summary field. It's necessary to check if the
                                //field that you want to modify exists, because not all implementations of this JSR
                                //include all fields
                                if (listaDeEventos.isSupportedField(Event.SUMMARY)) {  
                                        evento.setString(Event.SUMMARY,0,Event.ATTR_NONE,"Modified during pass#" + numeroCampo);
                                        Date ahora = new Date();
                                        evento.setDate(Event.REVISION,0,Event.ATTR_NONE,ahora.getTime()); //to indicate that the event was modified
                                }
                                evento.commit(); //store the value in persistent memory
                        }
                }      
               
                //create a new event lasting one hour on October 20 2008 at 1PM, with the personnel from maintenance
                //and an alert 30 minutes prior
               
                Event eventoNuevo = listaDeEventos.createEvent();

                /* It's important to check that the field you're hoping to modify exists, because it's not
                * a certain fact that other implementations of the JSR includes a field. The Motorola implementation
                * of this JSR includes the following fields:
                *  LOCATION (PIMItem.STRING)
                *  NOTE (PIMItem.STRING)
                *  SUMMARY (PIMItem.STRING)
                *  UID (PIMItem.STRING) (unique numerical identifier for event)
                *  END (PIMItem.DATE)
                *  START (PIMItem.DATE)
                *  REVISION (PIMItem.DATE)
                *  ALARM (PIMItem.INT) (in seconds prior to event start)
                *  CLASS (PIMItem.INT) (can be Event.CLASS_PUBLIC, Event.CLASS_PRIVATE, or Event.CLASS_CONFIDENTIAL)
                */

               
                Calendar horario = Calendar.getInstance();
                horario.set( Calendar.MONTH, Calendar.OCTOBER );
                horario.set( Calendar.DAY_OF_MONTH, 20 );
                horario.set( Calendar.YEAR, 2008 );
                horario.set( Calendar.HOUR_OF_DAY, 13 );
                horario.set( Calendar.MINUTE, 00 );
                horario.set( Calendar.SECOND, 00 );
                horario.set( Calendar.MILLISECOND, 0 );
                Date horaInicio = horario.getTime();
               
                horario.set( Calendar.MONTH, Calendar.OCTOBER );
                horario.set( Calendar.DAY_OF_MONTH, 20 );
                horario.set( Calendar.YEAR, 2008 );
                horario.set( Calendar.HOUR_OF_DAY, 14 );
                horario.set( Calendar.MINUTE, 00 );
                horario.set( Calendar.SECOND, 00 );
                horario.set( Calendar.MILLISECOND, 0 );
                Date horaFin = horario.getTime();
                Date horaRevision = new Date();  
               
                if (listaDeEventos.isSupportedField(Event.SUMMARY))
                  eventoNuevo.addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Meeting with maintenance");
                if (listaDeEventos.isSupportedField(Event.START))
                  eventoNuevo.addDate(Event.START, PIMItem.ATTR_NONE, horaInicio.getTime());
                if (listaDeEventos.isSupportedField(Event.END))
                  eventoNuevo.addDate(Event.END, PIMItem.ATTR_NONE, horaFin.getTime());
                if (listaDeEventos.isSupportedField(Event.ALARM))
                  eventoNuevo.addInt(Event.ALARM, PIMItem.ATTR_NONE, horaInicio.getTime() - (30 * 60)); //30 intervals of 60 seconds
                if (listaDeEventos.isSupportedField(Event.NOTE))
                  eventoNuevo.addString(Event.NOTE, PIMItem.ATTR_NONE, "Called by Carlos");
                if (listaDeEventos.isSupportedField(Event.REVISION))
                  eventoNuevo.addString(Event.REVISION, PIMItem.ATTR_NONE, horaRevision.getTime());
         
         eventoNuevo.commit();
  }
  catch (UnsupportedFieldException e) {
  //This error should never happen if we use isSupportedField() before modifying or adding fields, but it's a good practice to include this
                ...
  }
  catch (FieldFullException e) {
  //This is thrown wen there's no more index positions to add data to fhe field
                ...
  }
  catch (FieldEmptyException e){
        //thrown when we try to access a field that has no data
  }
  catch (PIMException e){
        //another error inside the PIM package classes
                /* the reason for the error can be one of a few:
                *
                * PIMException.FEATURE_NOT_SUPPORTED -- function doesn't exist in the implementation of the JSR
                * PIMException.GENERAL_ERROR -- generic error -- something bad happened
                * PIMException.LIST_CLOSED -- attempted access to an EventList, ContactList, ToDoList o PIMList item when it was closed
                * PIMException.LIST_NOT_ACCESSIBLE -- the EventList, ContactList, ToDoList o PIMLIst is not available (for example, the corresponding database was erased)
                * PIMException.MAX_CATEGORIES_EXCEEDED -- An attempt to add more categories than the maximum limit supported in the field
                * PIMException.UNSUPPORTED_VERSION -- The data are stored ina  version of PIM that is not supported by the JSR implementation.
                * PIMException.UPDATE_ERROR -- other reason that did not allow for the data to be updated in persistent memory.
                */

                int i = e.getReason();
  }

The methodology for accessing to a contacts list is similar.

0
Your rating: None