×
Namespaces

Variants
Actions

如何在来电时停止程序运行

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 3rd Edition MR, S60 3rd Edition FP1, S60 3rd Edition FP2 Beta
S60 3rd Edition FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)

文章
翻译:
hoolee
最后由 hamishwillee 在 09 Aug 2012 编辑
  • 详细描述

有时程序需要在来电时终止运行。下面这段示例代码演示了如何监视来电,以便响应。

  • MMP文件

需要下列链接库

LIBRARY etel3rdparty.lib


  • 头文件
#ifndef __TELOBSERVER_H_
#define __TELOBSERVER_H_
 
#include <e32base.h>
#include <Etel3rdParty.h>
 
class CTelObserver : public CActive
{
public:
/**
* Symbian OS default constructor
*/

CTelObserver();
 
/**
* 2nd phase constructor.
*/

static CTelObserver* NewL();
 
/**
* 2nd phase constructor.
*/

static CTelObserver* NewLC();
 
/**
* Destructor
*/

~CTelObserver();
 
/**
* Starts observing for the incoming calls.
*/

void StartListening();
 
private:
/**
* Symbian 2-phase constructor
*/

void ConstructL();
 
/**
* From CActive
*/

void RunL();
 
/**
* From CActive
*/

TInt RunError(TInt anError);
 
/**
* From CActive
*/

void DoCancel();
 
private: // Data
CTelephony* iTelephony;
 
CTelephony::TCallStatusV1 iCallStatus;
CTelephony::TCallStatusV1Pckg iCallStatusPkg;
};
 
#endif /*__TelObserver_H_*/
  • 源文件
#include <e32base.h>
#include <Etel3rdParty.h>
 
#include "TelObserver.h"
 
/**
* Constructor. Defines the priority for this active object.
*/

CTelObserver::CTelObserver() :
CActive(EPriorityStandard),
iCallStatusPkg(iCallStatus)
{
}
 
/**
* 2nd phase constructor.
*/

CTelObserver* CTelObserver::NewL()
{
CTelObserver* self = CTelObserver::NewLC();
CleanupStack::Pop(self);
return self;
}
 
/**
* 2nd phase constructor.
*/

CTelObserver* CTelObserver::NewLC()
{
CTelObserver* self = new (ELeave) CTelObserver();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
/**
* 2nd phase constructor.
*/

void CTelObserver::ConstructL()
{
iTelephony = CTelephony::NewL();
 
CActiveScheduler::Add(this);
}
 
/**
* Destructor.
*/

CTelObserver::~CTelObserver()
{
Cancel();
 
if (iTelephony)
delete iTelephony;
}
 
/**
* From CActive.
*/

void CTelObserver::RunL()
{
if (iStatus == KErrNone)
{
CTelephony::TCallStatus status = iCallStatus.iStatus;
 
switch (status)
{
case CTelephony::EStatusRinging:
{
// The phone is ringing. Pause the application.
// ...
break;
}
default:
{
// Not interested in other events.
break;
}
}
// Start listening for the next call
StartListening();
}
}
 
/**
* From CActive.
*/

TInt CTelObserver::RunError(TInt anError)
{
return anError;
}
 
/**
* From CActive.
*/

void CTelObserver::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
}
 
/**
* Starts observing for the incoming calls.
*/

void CTelObserver::StartListening()
{
iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange,
iCallStatusPkg);
SetActive();
}
This page was last modified on 9 August 2012, at 08:11.
69 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.

×