Categories: Symbian C++ | S60 3rd Edition | How To | Code Examples | Technical Solution | Files/Data
This page was last modified 13:04, 8 February 2008.
CS000817 - Installing and uninstalling MIDlets programmatically
From Forum Nokia Wiki
| ID | CS000817 | Creation date | February 8, 2008 |
| Platform | S60 3rd Edition | Tested on devices | |
| Category | Symbian C++ | Subcategory | Data&Files |
| APIs | Classes | ||
| Methods |
| Note! |
|---|
|
Description
The following code demonstrates how to install and uninstall a MIDlet programmatically using the Software Installer APIs.
Solution
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 User::LeaveIfError(iLauncher.Connect());
iOptions.iUpgrade = SwiUI::EPolicyNotAllowed; iOptions.iOCSP = SwiUI::EPolicyAllowed; iOptions.iDrive = 'C'; iOptionsPckg = iOptions;
iLauncher.SilentInstall( iStatus, KPathAndFileNameOfJarFile, iOptionsPckg ); SetActive();
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
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\\");
_LIT(KFileSpec1,"c:\\system\\install\\registry\\*.*");
User::LeaveIfError( fileSession.Connect() );
CleanupClosePushL( fileSession );
// Get the file list, sorted by name
User::LeaveIfError( fileSession.GetDir( KFileSpec1,
KEntryAttMaskSupported,
ESortByName, dirList ) );
CleanupStack::PushL(dirList);
for ( i=0; i < dirList->Count(); i++ )
{
fileName = (*dirList)[i].iName;
if( fileName.Compare(_L("temp")) == KErrNone )
{
continue;
}
fullPath = KDirName1;
fullPath.Append(fileName);
RFile lFile;
TInt err = lFile.Open( fileSession, fullPath, EFileShareAny | EFileRead );
if(err == KErrNone)
{
TInt lSize;
lFile.Size(lSize);
RBuf8 lBuf;
lBuf.Create(lSize);
lBuf.CleanupClosePushL();
lFile.Read(lBuf);//read contents into buffer
RBuf buff;
buff.Create(lSize);
buff.CleanupClosePushL();
buff.Copy(lBuf);//Copy into 16 bit buffer
lFile.Close();
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;
inst.Connect();
SwiUI::TUninstallOptions options;
SwiUI::TUninstallOptionsPckg optionsPckg;
options.iKillApp = SwiUI::EPolicyAllowed;
options.iBreakDependency = SwiUI::EPolicyAllowed;
optionsPckg = options;
TInt resp = inst.SilentUninstall( TUid::Uid(contextUid),
optionsPckg,
SwiUI::KJavaMIMEType );
inst.Close();
}
}
CleanupStack::PopAndDestroy(2); // buff, lBuf
}
}
CleanupStack::PopAndDestroy(2); // dirList, fileSession
}
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can 1 Application, split into 2 jar file (jar limitation) | juniar | Mobile Java General | 4 | 2004-05-10 12:04 |
| (Re)associating Python scripts with Python in messaging? | RaimondasL | Python | 3 | 2007-03-13 06:50 |
| Downloading midlets from WAP in Nokia 3410 | vtutin | Mobile Java General | 1 | 2002-10-19 05:10 |
| Sound problem in 6600 | ankur_k | Mobile Java Media (Graphics & Sounds) | 3 | 2004-01-20 14:23 |
| How to check text input mode programmatically? | f6696 | General Symbian C++ | 0 | 2002-12-13 06:13 |

