程序拨号及检测何时挂断的解决方案
来源:互联网 发布:mac os x ei capitan 编辑:程序博客网 时间:2024/05/16 17:54
用过Nokia智能手机的人都知道,当电话拨通以后,原来的程序就被切换到后台运行去了,但是当电话挂断以后,Nokia并没有把原来的程序给切换到前台,不知道Nokia为什么要这样做.本篇给出一份代码,内容包括拨号,CallBack电话挂断事件,把原来的程序切换到前台.
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.h
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#ifndef __DAILENGINE_H__
#define __DAILENGINE_H__
#include <etel.h>
class MPhoneCallClientObserver
{
public:
virtual void HandleCallHungUpL() = 0;
};
class CDailEngine:public CActive
{
public:
static CDailEngine* NewL(MPhoneCallClientObserver& aObserver);
~CDailEngine();
public:
// CActive
virtual void RunL();
virtual void DoCancel();
public:
void MakeCallL(const TDesC& aNumber);
private:
// the state of this object governs what happens when the
// StartL() / Stop() / RunL() / DoCancel() functions are called.
enum TState
{
ENoState,
EDialling,
EWatching
};
private:
CDailEngine(MPhoneCallClientObserver& aObserver);
void ConstructL();
private:
void StartL();
void Stop();
void InitCallServerL();
void TelephonyCleanup();
private:
MPhoneCallClientObserver& iObserver;
RCall iCall;
RTelServer iServer;
RPhone iPhone;
RLine iLine;
RCall::TStatus iCallStatus;
TState iState;
TPtrC iNumber;
};
#endif
/*
* ============================================================================
* Name : CDailEngine from CDailEngine.cpp
* Part of : None
* Created : 08.08.2006 by Zhaojiangwei
* Last Modifed: 22.08.2006
* Implementation notes:
*
* Version : 1.0
* Copyright: All rights reserved
* ============================================================================
*/
#include "DailEngine.h"
_LIT (KTsyName,"phonetsy.tsy");
CDailEngine::CDailEngine(MPhoneCallClientObserver& aObserver)
:CActive(EPriorityNormal),
iObserver(aObserver), iState(ENoState)
{
}
CDailEngine::~CDailEngine()
{
Cancel();
TelephonyCleanup();
}
CDailEngine* CDailEngine::NewL(MPhoneCallClientObserver& aObserver)
{
CDailEngine* self = new (ELeave) CDailEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
void CDailEngine::ConstructL()
{
CActiveScheduler::Add(this);
}
void CDailEngine::MakeCallL(const TDesC& aNumber)
{
iState = EDialling;
InitCallServerL();
iNumber.Set(aNumber);
StartL();
}
void CDailEngine::InitCallServerL()
{
iServer.Connect();
iServer.LoadPhoneModule(KTsyName);
//Find the number of phones available from the tel server
TInt numberPhones;
User::LeaveIfError(iServer.EnumeratePhones(numberPhones));
//Check there are available phones
if (numberPhones < 1)
{
User::Leave(KErrNotFound);
}
//Get info about the first available phone
RTelServer::TPhoneInfo info;
User::LeaveIfError(iServer.GetPhoneInfo(0, info));
//Use this info to open a connection to the phone, the phone is identified by its name
User::LeaveIfError(iPhone.Open(iServer, info.iName));
//Get info about the first line from the phone
RPhone::TLineInfo lineInfo;
User::LeaveIfError(iPhone.GetLineInfo(0, lineInfo));
//Use this to open a line
User::LeaveIfError(iLine.Open(iPhone, lineInfo.iName));
}
void CDailEngine::StartL()
{
switch(iState)
{
case ENoState:
return;
case EDialling:
{
User::LeaveIfError(iCall.OpenNewCall(iLine));
iCall.Dial(iStatus, iNumber);
break;
}
case EWatching:
iCall.NotifyStatusChange(iStatus, iCallStatus);
break;
}
SetActive();
}
void CDailEngine::RunL()
{
// if the caller hangs up, then we will get KErrGeneral error here
if(iState == EDialling && iStatus.Int() == KErrGeneral)
{
Stop();
iObserver.HandleCallHungUpL();
return;
}
if(iStatus.Int() != KErrNone)
return;
switch(iState)
{
case EDialling:
iState = EWatching;
StartL();
break;
case EWatching:
User::LeaveIfError(iCall.GetStatus(iCallStatus));
if(iCallStatus == RCall::EStatusHangingUp || iCallStatus == RCall::EStatusIdle)
{
Stop();
iObserver.HandleCallHungUpL();
}
else
{
StartL();
}
break;
default:
break;
}
}
void CDailEngine::DoCancel()
{
Stop();
}
void CDailEngine::Stop()
{
switch(iState)
{
case ENoState:
break;
case EDialling:
iCall.HangUp();
iCall.Close();
break;
case EWatching:
iCall.NotifyStatusChangeCancel();
iCall.Close();
break;
}
iState = ENoState;
}
void CDailEngine::TelephonyCleanup()
{
//free up the resource
iPhone.Close();
iLine.Close();
iServer.Close();
}
- 程序拨号及检测何时挂断的解决方案
- 程序拨号及检测何时挂断的解决方案
- 程序拨号及检测何时挂断的解决方案
- Android(AIDL)自动重复拨号及挂断/接听电话
- ppp-off拨号挂断脚本
- 建立GPRS连接,拨号和挂断
- WAVECOM CDMA AT指令--拨号&挂断
- 使用IntentFilter的拨号程序
- Android拨号程序的编写
- linphone快速挂断后的程序崩溃问题
- linphone快速挂断后的程序崩溃问题
- linphone快速挂断后的程序崩溃问题
- Linphone快速挂断后程序的崩溃问题
- nohup方式 真正的后台不挂断运行程序
- 中文pppoe中文拨号的解决方案
- 校园网无法拨号的一些解决方案
- Ubuntu提示检测到系统程序出现问题的解决方案
- Bash漏洞检测及解决方案
- SPI总线 SPI接口 SPI协议 SPI模式 SPI通讯
- OpenCV训练分类器
- {Linux内核“问题门”——学习问题、经验集锦} 给 fudan_abc的 一封信。
- NetBeans IDE 6.9 Beta 发布
- Sybase ASE学习总结(序)
- 程序拨号及检测何时挂断的解决方案
- 开始?
- 2010年4月23日(新公司入职,第三周星期五)
- C#多线程JOIN方法初探
- 背单词的软件,让记单词不再成为难事
- Haar分类器 ObjectMarker程序源代码
- 2010.4月编程语言排行
- 使用Qt编写服务器端程序(包括Http传输服务器端)的方法
- C#中DllImport用法和路径问题