监听MMC插入和拔出事件
文章信息
- 详细描述
应用程序可以使用RFs中的NotifyDiskSpace()方法来监控MMC卡的插入和拔出行为。
- 解决方案
为了收到这些事件,UI应用程序需要设置系统程序,以防拿出内存卡时造成程序自动关闭
CEikonEnv::Static()->SetSystem( ETrue );
执行上述步骤后,就按如下方式请求对内存卡插入和拔出的通知:
const TInt64 KThreshold = 0x1000; // Threshold value for free disk space
CEikonEnv::Static()->FsSession().NotifyDiskSpace(KThreshold, EDriveE, iStatus);
SetActive();
RFs::NotifyDiskSpace()是一个异步方法,可以检测threshold值的变化(在任一方向)
上述代码片段要放在从CActive派生的类中使用。
这些通知也可以从一个非UI程序中获得,只要创建一个window group即可,在派生自CActive类的构造过程中有:
// iWg is of type RWindowGroup*
// iWs is an open window server session (RWsSession)
// iFs is an open file server session (RFs)
iWg = new (ELeave) RWindowGroup( iWs );
User::LeaveIfError( iWg->Construct( (TUint32)iWg, EFalse ) );
iWg->SetOrdinalPosition( -1 );
iWg->EnableReceiptOfFocus( EFalse );
iWgName = CApaWindowGroupName::NewL( iWs );
iWgName->SetSystem( ETrue );
iWgName->SetHidden( ETrue );
iWgName->SetWindowGroupName( *iWg );
iFs.NotifyDiskSpace( KThreshold, EDriveE, iStatus );
SetActive();
完成CActive::RunL()如下:
if(iStatus == KErrNone)
{
// Threshold value has been crossed - memory card has been
// inserted or removed
iFs.NotifyDiskSpace(KThreshold, EDriveE, iStatus);
SetActive();
}
完成CActive::DoCancel()如下:
iFs.NotifyDiskSpaceCancel();

