Archived:Installing and uninstalling MIDlets programmatically

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Platform(s): S60 3rd Edition, S60 5th Edition
S60 3rd Edition (initial release)
Platform Security
Signing Required: DevCert
Capabilities: TrustedUI
Created: User:Technical writer 1 (February 8, 2008, updated April 23, 2009)
Last edited: hamishwillee (21 Jun 2012)

Note.pngNote: This API is not part of the public SDK. It can be found in the SDK API Plug-in.


The following code demonstrates how to install and uninstall a MIDlet programmatically using the Software Installer APIs.


Installing a MIDlet

A MIDlet can be installed using the SW installer APIs as below:

Capability requirements: TrustedUI

SwiUI::RSWInstSilentLauncher iLauncher; 
SwiUI::TInstallOptions iOptions;
SwiUI::TInstallOptionsPckg iOptionsPckg;
// Connect to software installer server
iOptions.iUpgrade = SwiUI::EPolicyNotAllowed;
iOptions.iOCSP = SwiUI::EPolicyAllowed;
iOptions.iDrive = 'C';
iOptionsPckg = iOptions;
iLauncher.SilentInstall( iStatus, KPathAndFileNameOfJarFile, iOptionsPckg );

The above code is meant to be run by an active object (derived from CActive) and uses the asynchronous version of SilentInstall() method.

It is also possible to install a MIDlet using the CDocumentHandler API. For more information on this API, refer to SDK Help.

Uninstalling a MIDlet

Note.pngNote: This method is deprecated and no longer works from S60 3rd Edition, Feature Pack 2 onwards.

When a MIDlet suite (possibly containing several MIDlets) is installed, the system creates a Suite UID for it and stores it in the Java registry. However, the only way to uninstall a MIDlet is to uninstall the parent MIDlet Suite. The MIDlet Suite UID must be passed to SwiUI::RSWInstSilentLauncher. However, this UID cannot be retrieved with methods from RApaLsSession.

Every time a MIDlet is installed, a new UID is generated for the application. Installer also creates some files for each installed MIDlet:

 C:\private\102033E6\MIDlets\[UID]\    (directory named with MIDlet Suite UID)

MIDlet .jar and .jad files are copied to this directory. It is possible to extract the MIDlet context (Suite) UID by searching the C:\System\install\registry\ directory for "<UID>.reg" files. If the MIDlet name appears inside the .reg file, it can be assumed that the registry file belongs to the correct MIDlet Suite. This UID can then be passed to SwiUI::RSWInstSilentLauncher in order to uninstall the Suite.

 void CJarUninstallAppUi::UninstallMIDletL()
RFs fileSession;
CDir* dirList;
TInt i;
TFileName fullPath;
TUint contextUid;
TFileName fileName;
_LIT(KDirName1, "c:\\system\\install\\registry\\");
User::LeaveIfError( fileSession.Connect() );
CleanupClosePushL( fileSession );
// Get the file list, sorted by name
User::LeaveIfError( fileSession.GetDir( KFileSpec1,
ESortByName, dirList ) );
for ( i=0; i < dirList->Count(); i++ )
fileName = (*dirList)[i].iName;
if( fileName.Compare(_L("temp")) == KErrNone )
fullPath = KDirName1;
RFile lFile;
TInt err = lFile.Open( fileSession, fullPath, EFileShareAny | EFileRead );
if(err == KErrNone)
TInt lSize;
RBuf8 lBuf;
lFile.Read(lBuf);//read contents into buffer
RBuf buff;
buff.Copy(lBuf);//Copy into 16 bit buffer
if (err == KErrNone)
// Check for MIDlet name in the file
err = buff.Find(_L("somemidlet.jar"));
if (err != KErrNotFound)
TLex lex( fileName.Mid(0,8) );
lex.Val( contextUid, EHex );
SwiUI::RSWInstSilentLauncher inst;
SwiUI::TUninstallOptions options;
SwiUI::TUninstallOptionsPckg optionsPckg;
options.iKillApp = SwiUI::EPolicyAllowed;
options.iBreakDependency = SwiUI::EPolicyAllowed;
optionsPckg = options;
TInt resp = inst.SilentUninstall( TUid::Uid(contextUid),
SwiUI::KJavaMIMEType );
CleanupStack::PopAndDestroy(2); // buff, lBuf
CleanupStack::PopAndDestroy(2); // dirList, fileSession
This page was last modified on 21 June 2012, at 09:26.
62 page views in the last 30 days.