×
Namespaces

Variants
Actions

Archived:Monitoring MMC insertion/removal events using Symbian C++

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

Remove from Archive?: This article has been marked for removal from archive, for the following reasons:
Looks like it would still be current to me.

Article Metadata
Tested with
Devices(s): All (S60)
Compatibility
Platform(s): S60 3rd Edition,
S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Article
Keywords: NotifyChange, ENotifyDisk
Created: User:Technical writer 1 (December 17, 2007
last updated: December 14, 2009)
Last edited: hamishwillee (20 Aug 2012)


Overview

Applications can be notified about the insertion or removal of the MMC using the RFs::NotifyChange() function, with ENotifyDisk used as the notify type (first parameter).


Solution

In order to receive these events, the UI application should be made a system application to prevent it from being automatically closed when removing a memory card.

 CEikonEnv::Static()->SetSystem( ETrue );

After this, notification requests for memory card insertion or removal can be implemented using the following active object (a class derived from CActive):

  #include <f32file.h>
 
class CMMCNotifier : public CActive
{
public: // Constructors and destructor
static CMMCNotifier * NewL();
~CMMCNotifier ();
public:
CMMCNotifier ();
void ConstructL();
 
public:
void RunL();
void DoCancel();
void IssueRequest();
 
private:
RFs iFs;
};

Implementation of notifier class

  CMMCNotifier::CMMCNotifier()
: CActive( CActive::EPriorityStandard )
{
CActiveScheduler::Add( this );
}
 
 
CMMCNotifier::~CMMCNotifier()
{
Cancel();
iFs.Close();
}
 
 
CMMCNotifier* CMMCNotifier::NewL()
{
CMMCNotifier* self = new (ELeave) CMMCNotifier;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
 
 
void CMMCNotifier::IssueRequest()
{
if ( !IsActive() )
{
// Request to get notified of MMC insertion/removal events
iFs.NotifyChange( ENotifyDisk, iStatus );
SetActive();
}
}
 
void CMMCNotifier::ConstructL()
{
User::LeaveIfError( iFs.Connect() );
}
 
 
void CMMCNotifier::DoCancel()
{
iFs.NotifyChangeCancel();
}
 
 
void CMMCNotifier::RunL()
{
TDriveInfo driveInfo;
// Get the drive info for memory card
TInt err = iFs.Drive( driveInfo, EDriveE );
if( err == KErrNone )
{
switch( driveInfo.iType )
{
case EMediaNotPresent:
{
//MMC removed
break;
}
default:
{
//MMC inserted
break;
}
}
}
// Issue request for next event notification
IssueRequest();
}


This page was last modified on 20 August 2012, at 05:20.
58 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.

×