×
Namespaces

Variants
Actions
Revision as of 06:19, 6 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

使用CTelephony获取网络名

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

代码示例
文章
翻译:
hoolee
最后由 hamishwillee 在 06 Aug 2012 编辑

Needs-update.png本文需要更新: 如果您发现这篇文章有用,请修复下面的问题,然后从文章中删除 {{ArticleNeedsUpdate}} 模板,以消除此警告。

原因: hamishwillee (21 Dec 2011)
Needs to be merged with near-duplicate topic 从CTelephony获取网络名

  • 简介

CTelephonyReader演示了如何用第三版CTelephony API来获取网络名称。

功能的完成很简单,使用这个函数只需要完成回调接口,并在一开始构造出CTelephonyReader实例即可。

注意:代码无法再模拟器正常工作,你只能在真机测试。

  • 需要的头文件
#include <Etel3rdParty.h>
  • 需要的链接库
LIBRARY etel3rdparty.lib


  • 需要的能力
Capability ReadDeviceData
  • TelephonyReader.h
#ifndef __TELEPHONYREADER_h__
#define __TELEPHONYREADER_h__
 
#include <Etel3rdParty.h>
class MTelephonyObserver
{
public:
virtual void GetCurrentNetworkName(const TDesC& aNetworkName) = 0;
 
};
 
class CTelephonyReader : public CActive
{
public:
static CTelephonyReader* NewL(MTelephonyObserver* aObserver);
static CTelephonyReader* NewLC(MTelephonyObserver* aObserver);
void ConstructL(void);
~CTelephonyReader();
protected:
void DoCancel();
void RunL();
 
private:
CTelephonyReader(MTelephonyObserver* aObserver);
 
private:
MTelephonyObserver* iObserver;
CTelephony* iTelephony;
CTelephony::TNetworkNameV1 iNetworkNameV1;
CTelephony::TNetworkNameV1Pckg iNetworkNameV1Pckg;
};
 
#endif //__TELEPHONYREADER_h__
  • TelephonyReader.cpp
#include "TelephonyReader.h" 
 
CTelephonyReader* CTelephonyReader::NewL(MTelephonyObserver* aObserver)
{
CTelephonyReader* self = NewLC(aObserver);
CleanupStack::Pop(self);
return self;
}
 
 
CTelephonyReader* CTelephonyReader::NewLC(MTelephonyObserver* aObserver)
{
CTelephonyReader* self = new (ELeave) CTelephonyReader(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
 
CTelephonyReader::CTelephonyReader(MTelephonyObserver* aObserver)
:CActive(0),iObserver(aObserver),iNetworkNameV1Pckg(iNetworkNameV1)
{
}
 
CTelephonyReader::~CTelephonyReader()
{
Cancel();
delete iTelephony;
}
 
void CTelephonyReader::ConstructL(void)
{
CActiveScheduler::Add(this);
 
iTelephony = CTelephony::NewL();
 
iTelephony->GetCurrentNetworkName(iStatus,iNetworkNameV1Pckg);
 
SetActive();
}
 
void CTelephonyReader::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkNameCancel );
}
 
 
void CTelephonyReader::RunL()
{
if(iStatus == KErrNone)
{
iObserver->GetCurrentNetworkName(iNetworkNameV1.iNetworkName);
}
}
  • 实例代码

Media:MyTelephonyNetworkName.zip (example code)

This page was last modified on 6 August 2012, at 06:19.
178 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.

×