×
Namespaces

Variants
Actions
(Difference between revisions)

第三版中如何获取Cell ID

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Automated change of category from Lang-CN to Unlikely Category)
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix broken external link)
Line 1: Line 1:
[[Category:Location]][[Category:Symbian C++]][[Category:Telephony]]
+
[[Category:Location]][[Category:Symbian C++]][[Category:Telephony]][[Category:Lang-Chinese]][[Category:Code Snippet]]
 
当了找出[[S60]]第三版手机当前的cell ID,程序必须要有Symbian签名。因为需要有ReadDeviceData能力。程序员必须使用[[active object]]因为这个调用要异步处理。下面是一个获取cell id的示例。
 
当了找出[[S60]]第三版手机当前的cell ID,程序必须要有Symbian签名。因为需要有ReadDeviceData能力。程序员必须使用[[active object]]因为这个调用要异步处理。下面是一个获取cell id的示例。
  
Line 148: Line 148:
 
== 外部链接 ==
 
== 外部链接 ==
  
* [http://blogs.forum.nokia.com/view_entry.html?id=421 DevInfo - Get the IMEI, IMSI, CellId etc., synchronously on 3.x devices]
 
  
 +
* Get the IMEI, IMSI, CellId etc., synchronously on 3.x devices (Blog no longer available, content reproduced below:)
 +
<toggledisplay>In this blog entry I would like to share a small utility class, which is nothing but to find the Phone/Network/Subscriber related information in a synchronous way. In Forum Nokia Technical Library there is already a tip for finding the IMEI number in synchronously, you can find it here. I've just used that approach here to find these details: Phone information: manufacturer, model and serial number (IMEI). You've to basically use the CTelephony::GetPhoneId() API to get these information. Network information: cell id, location area code, country code etc. (this can be extended, check the SDK Help of CTelephony for that). With CTelephony::GetCurrentNetworkInfo() API you can gather the network related information. Notice here you need a ReadDeviceData capability for accessing this function. Subscriber information: subscriber id (IMSI).
  
 +
The CTelephony::GetSubscriberId() API will help you retrieve this information. All the above functions are not synchronous so to make it synchronous the work-around is the use of CActiveSchedulerWait. After the call of these asynchronous and SetActive() you have to call a iActiveSchedulerWait->Start() and in your RunL() you have to check whether the iActiveSchedulerWait is already started with iActiveSchedulerWait->IsStarted() if then stop by iActiveSchedulerWait->Stop(), then fetch the information.
  
[[Category:Code_Examples]]
+
Get to know more about this please refer this example: DevInfo_3.x. Please check my comments below for more clarity.    EDIT: Changed the article name (previously it was Get the IMEI of a 3.x device) and added a more elaborated and extended example.</toggledisplay>
[[Category:Lang-Chinese]]
+

Revision as of 07:50, 2 August 2011

当了找出S60第三版手机当前的cell ID,程序必须要有Symbian签名。因为需要有ReadDeviceData能力。程序员必须使用active object因为这个调用要异步处理。下面是一个获取cell id的示例。

需要的头文件:

#include<etel3rdparty.h>

所需链接库:

LIBRARY  etel3rdparty.lib

所需能力:

Capability  ReadDeviceData

NetworkInfo.h

#ifndef __NETWORKINFO_H__
#define __NETWORKINFO_H__
 
#include <etel3rdparty.h> // CTelephony
 
// Observer interface
class MNetworkInfoObserver
{
public:
virtual void NetworkInfoRetrievedL(
const CTelephony::TNetworkInfoV1& aNetworkInfo) = 0;
virtual void HandleNetworkInfoError(TInt aError) = 0;
};
 
// Active object to get network info
class CNetworkInfo : public CActive
{
public:
static CNetworkInfo* NewL();
~CNetworkInfo();
 
void GetNetworkInfoL(MNetworkInfoObserver* aObserver);
 
protected:
// from CActive
void RunL();
TInt RunError(TInt aError);
void DoCancel();
 
private:
CNetworkInfo();
void ConstructL();
 
private:
CTelephony* iTelephony;
CTelephony::TNetworkInfoV1 iNwInfo;
CTelephony::TNetworkInfoV1Pckg iNwInfoPckg;
MNetworkInfoObserver* iObserver;
};
 
#endif // __NETWORKINFO_H__

NetworkInfo.cpp

#include "NetworkInfo.h"
 
CNetworkInfo::CNetworkInfo()
: CActive(EPriorityStandard),
iNwInfoPckg(iNwInfo)
{
CActiveScheduler::Add(this);
}
 
CNetworkInfo* CNetworkInfo::NewL()
{
CNetworkInfo* self = new (ELeave) CNetworkInfo;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
 
void CNetworkInfo::ConstructL()
{
iTelephony = CTelephony::NewL();
}
 
CNetworkInfo::~CNetworkInfo()
{
Cancel();
delete iTelephony;
}
 
// This function is used by our class' users to start getting network info.
void CNetworkInfo::GetNetworkInfoL(MNetworkInfoObserver* aObserver)
{
__ASSERT_ALWAYS(!IsActive(), User::Leave(KErrInUse));
iObserver = aObserver;
 
// Start async call to receive current network information
iTelephony->GetCurrentNetworkInfo(iStatus, iNwInfoPckg);
SetActive();
}
 
void CNetworkInfo::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
}
 
void CNetworkInfo::RunL()
{
User::LeaveIfError(iStatus.Int());
// Request completed successfully.
// Now we can notify our observer.
if(iObserver)
{
iObserver->NetworkInfoRetrievedL(iNwInfoPckg());
}
}
 
TInt CNetworkInfo::RunError(TInt aError)
{
// There was an error retrieving current network info.
// Let's inform our observer about the error so that it can analyze it
// and try to recover.
if(iObserver)
{
iObserver->HandleNetworkInfoError(aError);
}
 
return KErrNone;
}


相关链接

外部链接

  • Get the IMEI, IMSI, CellId etc., synchronously on 3.x devices (Blog no longer available, content reproduced below:)
[show details]
102 page views in the last 30 days.