×
Namespaces

Variants
Actions

Monitoring memory card insertion/removal events

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

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


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

Overview

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.

Solution

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());
iDiskDetector->Start();

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()   
{
Cancel();
iFs.NotifyChange(ENotifyDisk, iStatus);
SetActive();
}


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

void CDiskDetector::RunL()   
{
TInt err = iStatus.Int();
if(err!=KErrCancel)
{
iObserver.NotifyDiskChange();
}
}

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()   
{
iDiskDetector->Start();
TVolumeInfo vol;
TInt err = iCoeEnv->FsSession().Volume(vol, EDriveE);
if(err==KErrNone)
{
// 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):

HelloWorld(DiskChange).zip


Related article:

TSS000794 - Monitoring MMC insertion / removal events

This page was last modified on 30 May 2013, at 07:34.
35 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.

×