为了方便使用我将IMEI的查询也加入到原作者的的代码中,以方便我们的使用。以下代码来自于诺基亚论坛,代码原作者是chenziteng
,现转载其源代码于下(本人稍作修改):
头文件如下:
#ifndef MYTELEPHONY_H#define MYTELEPHONY_H#include #include
class CMyTelephony : public CActive {public: static void
GetIMSIL(TDes& aIMSI); static void GetIMEIL(TDes& aIMEI); static void
GetPhoneType(TDes& aPhoneType); static void DialPhone(const TDesC&
aPhoneId); static CMyTelephony* NewL();protected: void DoCancel(); void
RunL();private: static CMyTelephony* NewLC();~CMyTelephony(); CMyTelephony();
void ConstructL();void GetSubscriberId(); void GetPhoneId();private: CTelephony*
iTelephony; CTelephony::TCancellationRequest iRequest;
CTelephony::TSubscriberIdV1 iSubscriberId; CTelephony::TSubscriberIdV1Pckg
iSubscriberIdPckg; CTelephony::TPhoneIdV1 iPhoneId; CTelephony::TPhoneIdV1Pckg
iPhoneIdPckg; CTelephony::TCallId iCallId; TBuf<32> iPhoneType;public :
void DialNewCall(const TDesC& aTelNumber); };#endif // MYTELEPHONY_H
cpp源文件如下:
// MyTelephony.cpp//#include #include "MyTelephony.h"#include
class CTelephony;CMyTelephony* CMyTelephony::NewLC() { CMyTelephony*
self = new (ELeave) CMyTelephony; CleanupStack::PushL(self);
self->ConstructL(); return self; }CMyTelephony* CMyTelephony::NewL() {
CMyTelephony* self = CMyTelephony::NewLC(); CleanupStack::Pop(self); return
self; }void CMyTelephony::GetIMSIL(TDes& aIMSI) {#ifdef __WINS__
CMyTelephony* telephony = CMyTelephony::NewL(); telephony->GetSubscriberId();
aIMSI = telephony->iSubscriberId.iSubscriberId;delete telephony;#else
_LIT(KDebugIMSI, "000000000000000"); aIMSI = KDebugIMSI;#endif }void
CMyTelephony::GetIMEIL(TDes& aIMEI) {#ifndef __WINS__ //真实设备 This only works
on target machine CMyTelephony* telephony = CMyTelephony::NewL();