Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Monitoring memory card insertion/removal events

From 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}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Platform(s): S60
Keywords: RFs::NotifyChange, ENotifyDisk
Created: chenziteng (23 Sep 2009)
Last edited: hamishwillee (30 May 2013)


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

iFs.NotifyChange(ENotifyDisk, iStatus);   

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...

void CDiskDetector::Start()   
iFs.NotifyChange(ENotifyDisk, iStatus);

The RunL() method of the active object can be as follows,

void CDiskDetector::RunL()   
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,

void CHelloWorldAppUi::NotifyDiskChange()   
TVolumeInfo vol;
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

Source Code

You can download the full example program here (the code has been verified on a S60 5th Edition device):


Related article:

TSS000794 - Monitoring MMC insertion / removal events

This page was last modified on 30 May 2013, at 04:34.
32 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.