Hello Everyone,
I have been trying to retrieve cellId by using CTelephony class . So far i have been able to do this. Its executing with no problems but its returning a wrong CellId everytime. i.e - '0'.. Please help
following are the code files ..
CellidDetector.h
the CellidDetector.cppCode:/* ============================================================================ Name : CellidDetector.h Author : Abhishek karmakar Version : 1.0 Copyright : Your copyright notice Description : CCellidDetector declaration ============================================================================ */ #ifndef CELLIDDETECTOR_H #define CELLIDDETECTOR_H #include <e32base.h> // For CActive, link against: euser.lib #include <e32std.h> // For RTimer, link against: euser.lib #include <Etel3rdParty.h> // Starting from S60 2nd Edition, access to telephony functionality and device IMEI/IMSI information was supposed to be provided by the ETEL third-party telephony library (etel3rdparty.dll, class CTelephony). #include <etelbgsm.h> class CCellidDetector : public CActive { public: // Cancel and destroy ~CCellidDetector(); // Two-phased constructor. static CCellidDetector* NewL(); // Two-phased constructor. static CCellidDetector* NewLC(); public: // New functions // Function for making the initial request void StartL(); TUint GetNetworkCellId(TUint& aCellId); private: // C++ constructor CCellidDetector(); // Second-phase constructor void ConstructL(); private: // From CActive // Handle completion void RunL(); // How to cancel me void DoCancel(); // Override to handle leaves from RunL(). Default implementation causes // the active scheduler to panic. TInt RunError(TInt aError); private: enum TCellidDetectorState { EGetPhoneInfo, EDone // Error condition }; private: TInt iState; // State of the active object RTimer iTimer; // Provides async timing service //TInt iState; // Pointer to a newly created CTelephony object. CTelephony * iTelephony; // Defines information related to a mobile phone network. CTelephony::TNetworkInfoV1 iNetworkInfo; // Controls a single scheduling loop in the current active scheduler. CActiveSchedulerWait iActiveSchedulerWait; // On GSM/WCDMA networks, the cell identity code. TUint iCellId; }; #endif // CELLIDDETECTOR_H
And in the appuid i have added a new button where i am writing this code ..Code:/* ============================================================================ Name : CellidDetector.cpp Author : Abhishek karmakar Version : 1.0 Copyright : Your copyright notice Description : CCellidDetector implementation ============================================================================ */ #include "CellidDetector.h" CCellidDetector::CCellidDetector() : CActive(EPriorityStandard) // Standard priority { } CCellidDetector* CCellidDetector::NewLC() { CCellidDetector* self = new (ELeave) CCellidDetector(); CleanupStack::PushL(self); self->ConstructL(); return self; } CCellidDetector* CCellidDetector::NewL() { CCellidDetector* self = CCellidDetector::NewLC(); CleanupStack::Pop(); // self; return self; } void CCellidDetector::ConstructL() { User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer iTelephony = CTelephony::NewL(); CActiveScheduler::Add(this); // Add to scheduler } CCellidDetector::~CCellidDetector() { Cancel(); // Cancel any request, if outstanding iTimer.Close(); // Destroy the RTimer object // Delete instance variables if any } void CCellidDetector::DoCancel() { //iTimer.Cancel(); iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel); } void CCellidDetector::StartL() { Cancel(); // Cancel any request, just to be sure iState = EGetPhoneInfo; CTelephony::TNetworkInfoV1Pckg networkInfoPckg(iNetworkInfo); //A typedef'd packaged CTelephony::TNetworkInfoV1 for passing through a generic API method. iTelephony->GetCurrentNetworkInfo(iStatus, networkInfoPckg); //Retrieve over-the-air network information about the currently registered mobile network. SetActive(); // Tell scheduler a request is active iActiveSchedulerWait.Start(); } void CCellidDetector::RunL() { iState = EDone; if (iActiveSchedulerWait.IsStarted()) // Reports whether this CActiveSchedulerWait object is currently started. { iActiveSchedulerWait.AsyncStop(); // Stops the scheduling loop owned by this object. if (iStatus == KErrNone) { iCellId = iNetworkInfo.iCellId; } else { // ***********Handle Error here ************ } } } TInt CCellidDetector::RunError(TInt aError) { return aError; } TUint CCellidDetector::GetNetworkCellId(TUint& aCellId) { StartL(); aCellId = iCellId; return aCellId; }
headers used..Code:TUint cellId; TUint hasil; CCellidDetector* devCellidUtility = CCellidDetector::NewL(); CleanupStack::PushL(devCellidUtility); hasil = devCellidUtility->GetNetworkCellId(cellId); CleanupStack::PopAndDestroy(devCellidUtility); _LIT(KFormatString, "CellId : %d"); TBuf <50> aString; aString.Format(KFormatString, hasil); CAknConfirmationNote* note1 = new (ELeave) CAknConfirmationNote( ETrue ); //Waiting note1->ExecuteLD(aString);
its returning the CellId as 0 ..Code:#include <Etel3rdParty.h> #include <etelbgsm.h>
Please help ..
Many thanks ..
Abhishek karmakar





