Monitoring memory card insertion/removal events
This article discusses how an application can monitor the insertion and removal of memory card.
Applications can be notified about the insertion or removal of the memory card using the RFs::NotifyChange(ENotifyDisk, ...) method.
Convert application to system application
In order to receive memory card insertion and removal events, the UI application should be made a system application to prevent it from being automatically closed when removing a memory card.
Add following code to the ConstructL of the AppUI class.
// don't close me when the memory card is removed
CEikonEnv::Static()->SetSystem( ETrue );
iDiskDetector = CDiskDetector::NewL(*this, iCoeEnv->FsSession());
Add notifier to the application
In order to receive the events a notifier needs to be added to the application. This can be done by calling following code fragment
NotifyChange() is an asynchronous method that completes when the availability of the memory card is changed. The above code snippet is meant to be used inside a CActive-derived class. Such as...
The RunL() method of the active object can be as follows,
TInt err = iStatus.Int();
Check for memory card inside notifier
When the memory card is inserted / removed, the notifier / observer generates an event NotifyDiskChange. Inside this event handler the observer can then check the availability of the memory card using RFs::Volume,
TInt err = iCoeEnv->FsSession().Volume(vol, EDriveE);
// the memory card is available
else // generally the err should be KErrNotReady
// the memory card is NOT available
You can download the full example program here (the code has been verified on a S60 5th Edition device):