×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    1

    Unhappy How save IMEI in a text file with symbian exe program?

    Hi all,
    Is it possibile to retrieve IMEI code from a symbian S60 2nd FP2/FP3 (like N70 or 6630) exe program (I'm using int E32Main() function) and print it on a static text file? I need to do it during the installation, with this PKG line:
    Code:
    ".\getimei.exe"-"c:\imei.exe", FILERUN, RUNINSTALL
    I've tried 4 different ways to do it, but they all didn't work out:

    1st way (compile but not works):
    Code:
    #include <e32base.h>
    #include <Etel3rdParty.h>
    #include <f32file.h>
    
    //----------------------------
    class C_imei: public CActive{
    private:
       CTelephony *telephony;
       CTelephony::TPhoneIdV1 iV1;
       CTelephony::TPhoneIdV1Pckg iPkg;
       TBuf<50> imei;
    
       CActiveSchedulerWait asw;
    public:
       C_imei::C_imei():
          CActive(EPriorityStandard),
          telephony(NULL),
          iPkg(iV1)
       {}
    
       void ConstructL(){
          telephony = CTelephony::NewL();
       }
    
       ~C_imei(){
          Cancel();
          delete telephony;
       }
    
       void GetIMEI(TDes8 &str){
          CActiveScheduler::Add(this);
          telephony->GetPhoneId(iStatus, iPkg);
          SetActive();
          asw.Start();
          Deque();
          //const wchar_t *wp = (wchar_t*)imei.PtrZ();
          //str.Copy(wp);
          str.Copy(imei);
       }
    
       void DoCancel(){
          telephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
       }
    
       void RunL(){
          if(iStatus == KErrNone)
             imei = iPkg().iSerialNumber;
          asw.AsyncStop();
       }
    };
    //----------------------------
    
    void ReadDeviceSerialNumber(TDes8 &imei){
    
       C_imei *im = new(ELeave) C_imei;
       CleanupStack::PushL(im);
       im->ConstructL();
       CleanupStack::Pop(im);
       im->GetIMEI(imei);
       delete im;
    }
    
    int E32Main()
    {
    	TBuf8<50> imei;
    	RFile file;
    	RFs fsSession;
    
    	ReadDeviceSerialNumber(imei);
    	fsSession.Connect();
    	_LIT(fileName, "info.txt");
    	file.Create(fsSession,fileName,EFileStreamText|EFileWrite|EFileShareAny);
    	file.Write(imei);
    	file.Close();
    	return 0;
    }
    2nd way (with PlpVariant lib, compiles but not works):
    Code:
    #include <plpvariant.h>
    #include <f32file.h>
    #include <e32base.h>
    
    int E32Main()
    {
    	TBuf<128>/*PlpVariantMachineId*/ imei;
    	TBuf8<128> imei8;
    	RFile file;
    	RFs fsSession;
    
    	PlpVariant::GetMachineIdL(imei);
    	imei8.Copy(imei);
    	fsSession.Connect();
    	_LIT(fileName, "info.txt");
    	file.Create(fsSession,fileName,EFileStreamText|EFileWrite|EFileShareAny);
    	file.Write(imei8);
    	file.Close();
    	return 0;
    }
    3rd way (compile but not works):

    getimei.h file:
    Code:
    #include <Etel3rdParty.h>
    #include <f32file.h>
    #include <e32base.h>
    #define DELETE_NULL(ptr)    { delete ptr; ptr = NULL; }
    
    class CGetIMEI : public CActive
    {
    public:
    	static CGetIMEI* NewL(/*TDes& aIMEI*/);
    
    	// Cancel and destroy
    	~CGetIMEI();
    
    public: // New functions
    	// Function for making the initial request
    	void StartL();
    
    	const TPtrC GetIMEI();
    
    private:
    	// C++ constructor
    	CGetIMEI(/*TDes& aIMEI*/);
    	// Second-phase constructor
    	void ConstructL();
    
    	// 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.
    	//void RunError(TInt aError);
    
    private:
    	enum TGetIMEIState
    	{
    		EStart = 1,
    	    EGetPhoneInfo,
    		EDone
    	};
    
    private:
    	TInt    iState;		// State of the active object
    	CTelephony* iTelephony;
    	CTelephony::TPhoneIdV1 iPhoneId;
    	CActiveSchedulerWait iActiveSchedulerWait;
    	TBuf<CTelephony::KPhoneSerialNumberSize> iIMEI;
    	//CMobile7AppUi* iAppUi;
    
    };
    getimei.c file:
    Code:
    #include "getimei.h"
    
    CGetIMEI* CGetIMEI::NewL(/*TDes& aIMEI*/)
    {
    	CGetIMEI* self = new (ELeave) CGetIMEI(/*aIMEI*/);
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	CleanupStack::Pop(self);
    
    	return self;
    }
    
    CGetIMEI::CGetIMEI() : CActive(EPriorityHigh)	// HIGH priority
    	/*,iIMEI(aIMEI)*/
    {
    	iIMEI.Zero();
    	iState = EStart;
    }
    
    void CGetIMEI::ConstructL()
    {
    	iTelephony = CTelephony::NewL();
    	CActiveScheduler::Add(this);				// Add to scheduler
    }
    
    CGetIMEI::~CGetIMEI()
    {
    	Cancel(); // Cancel any request, if outstanding
    	// Delete instance variables if any
    	DELETE_NULL(iTelephony);
    }
    
    void CGetIMEI::DoCancel()
    {
    	iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
    }
    
    void CGetIMEI::StartL()
    {
    	Cancel();						// Cancel any request, just to be sure
    	iState = EGetPhoneInfo;
    	CTelephony::TPhoneIdV1Pckg phoneIdPckg( iPhoneId );
    	iTelephony->GetPhoneId(iStatus, phoneIdPckg);
    	SetActive();					// Tell scheduler a request is active
    	iActiveSchedulerWait.Start();
    }
    
    void CGetIMEI::RunL()
    {
    	iState = EDone;
    	if ( iActiveSchedulerWait.IsStarted() )
    	{
    		iActiveSchedulerWait.AsyncStop();
    		if(iStatus == KErrNone)
    		{
    			iIMEI.Append(iPhoneId.iSerialNumber);
    			//iAppUi->iIMEI.Append(iPhoneId.iSerialNumber);
    		}/*
    		else
    		{
    			TBuf<64> buf;
    			buf.Num(iStatus.Int());
    			_LIT(KE,"Get Phone Info error:");
    			CEikonEnv::Static()->InfoWinL(KE(),buf);
    		}*/
    	}
    }
    
    const TPtrC CGetIMEI::GetIMEI()
    {
    	StartL();
    	TPtrC ptr(iIMEI.Ptr());
    	return ptr;
    }
    
    int E32Main() {
    	CGetIMEI* getIMEI = CGetIMEI::NewL();
    	TBuf16<30> imei;
    	TBuf8<30> imei8;
    	RFile file;
    	RFs fsSession;
    
    	imei.Copy(getIMEI->GetIMEI());
    	imei8.Copy(imei);
    	fsSession.Connect();
    	_LIT(fileName, "info.txt");
    	file.Create(fsSession,fileName,EFileStreamText|EFileWrite|EFileShareAny);
    	file.Write(imei8);
    	file.Close();
    	return 0;
    }
    4th way (compiles but not work, I'm close to suicide):

    getimei.h file:
    Code:
    #include <etel3rdparty.h>
    #include <f32file.h>
    #include <e32base.h>
    
    /* Declare the client class */
    class CIMEI : public CActive
    {
    public:
    	CIMEI();
    
    	// Construction
    	void ConstructL();
    
    	// Destruction
    	~CIMEI();
    
    	static CIMEI* NewL();
    
    	// Issue request: retrieve IMEI
    	void GetIMEI();
    
    	// Cancel request
    	void DoCancel();
    
    	// Service completed request
    	void RunL();
    
    	TBool IsRetrieved() { return iRetrieved;}
    
    private:
    	CTelephony* iTelephony; // telephony object we own
    	CTelephony::TPhoneIdV1 iV1;
    	CTelephony::TPhoneIdV1Pckg* iPkg;
    	TBool iRetrieved;
    
    public:
    	TBuf<20> retrievedIMEI;
    };
    getimei.cpp file:
    Code:
    #include "getimei.h"
    
    /* Define the client class */
    
    CIMEI::CIMEI() : CActive(EPriorityStandard)
    {
    	iRetrieved = EFalse;
    }
    
    CIMEI* CIMEI::NewL()
    {
    	CIMEI* self =new(ELeave) CIMEI();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	CleanupStack::Pop(self);
    	return self;
    }
    
    void CIMEI::ConstructL()
    {
    	iPkg = new (ELeave) CTelephony::TPhoneIdV1Pckg(iV1);
    	iTelephony = CTelephony::NewL();
    	CActiveScheduler::Add(this);
    }
    
    CIMEI::~CIMEI()
    {
    	Cancel(); // if any request outstanding, calls DoCancel() to cleanup
    	delete iTelephony;
    	delete iPkg;
    }
    
    void CIMEI::GetIMEI()
    {
    	iTelephony->GetPhoneId( iStatus, *iPkg );
    	SetActive();
    	CActiveScheduler::Start();
    }
    
    void CIMEI::RunL()
    {
    	if ( (iStatus == KErrNone) )
    	{
    		retrievedIMEI = (*iPkg)().iSerialNumber; // Read IMEI from package buffer
    	}
    	CActiveScheduler::Stop();
    
    	iRetrieved = ETrue;
    }
    
    void CIMEI::DoCancel()
    {
    	Cancel();
    }
    
    int E32Main()
    {
    	TBuf8<20> imei8;
    	RFile file;
    	RFs fsSession;
    	CIMEI* imei = CIMEI::NewL();
    	imei->GetIMEI();
    
    	do
    	{
    	} while (!imei->IsRetrieved());
    
    	TBuf<20> imeistr(imei->retrievedIMEI);
    	fsSession.Connect();
    
    	delete imei;
    	imei = NULL;
    	imei8.Copy(imeistr);
    	_LIT(fileName, "info.txt");
    file.Create(fsSession,fileName,EFileStreamText|EFileWrite|EFileShareAny);
    	file.Write(imei8);
    	file.Close();
    	return 0;
    }
    I found these classes on internet, but I've found many difficulties with Symbian C++ programming... I know that using CTelephony classes I made asyncronous requests (I hoped to resolve this with the do-while, but it didn't work again), but what about PlpVariant library?
    Thank you for help.
    Sorry for the great quantity of code and sorry for my terrible english o_O...

    Simone

  2. #2
    Super Contributor
    Join Date
    May 2003
    Location
    Vancouver, Canada
    Posts
    985

    Re: How save IMEI in a text file with symbian exe program?

    First of all, please do not suicide...

    1st way: You should copy the IMEI number in RunL() function. The GetPhoneId() is an asynchronous function, so the IMEI number does not return immediately.

    2nd way: Not sure if PlpVariant can still be used. I think it is deprecated already.

    3rd way: The same problem as the 1st way. The IMEI number is returned in RunL() function. So you have to copy it in RunL().

    4th way: The problem in the active object usage. The problem is that you have "do while" in the main program waiting for IsRequested() to return true. This actually blocks the active object (CIMEI) so that your application will just hang.

    My suggestion is use User::WaitForRequest() to wait for the signal from active object in the 4th way.

    Also read some documentation about active object. These are some good links about active object:

    http://newlc.com/ActiveObjects.html
    http://forum.nokia.com/info/sw.nokia...0b_en.zip.html

    Antony

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: How save IMEI in a text file with symbian exe program?

    Hi simone.lai,

    Try out with following code: (Plpvariant)

    Headers:
    #include <plpvariant.h> //For getting IMEI
    #include <f32file.h> //For File Handling
    Libraries:
    LIBRARY efsrv.lib //For File Handling
    LIBRARY PlpVariant.lib //For getting IMEI
    Code:
    	TBuf16<20> iImei16;
    	//For getting IMEI- to be appended in the SMS
    	#ifndef __WINS__
    	  // This only works on target machine
    	  TPlpVariantMachineId machineid;
    	  PlpVariant::GetMachineIdL(machineid);	  	  
    	#else
    	  // Return a fake IMEI when working on emulator
    	  _LIT(machineid, "123450987685263");
    	#endif	
    
    	iImei16.Copy(machineid);
    
    	TBuf8<20> iImei8;
    	iImei8.Copy(iImei16);
    	_LIT(KTest,"c:\\system\\TestFile.txt");
    	RFs aFs;
    	aFs.Connect();
    	RFile file;
    	TInt cErr= file.Open(aFs,KTest,EFileWrite);//Assuming that File is already there
    	if(cErr==KErrNone)
    	{
    		file.Write(iImei8);
    		file.Close();
    	}
    	aFs.Close();
        }
    It works fine with me on 2nd FP2/FP3 devices.

    Regards.
    Kiran.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    Re: How print IMSI on emulator

    please help me..
    I have created a symbian OS C++ project--->GUI Application whit UI designer that create project that show on emulator Hello World whit Carbide. Now i wont use this project for print IMSI and not HelloWorld... I'm don't able to do it...
    Can anyone help my please????

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    please help me..
    I have created a symbian OS C++ project--->GUI Application whit UI designer that create project that show on emulator Hello World whit Carbide. Now i wont use this project for print IMSI and not HelloWorld... I'm don't able to do it...
    Can anyone help my please????
    I guess that you are working on S60 3rd edition. Check this: Reading IMSI in 3rd Edition

    For step by step representation, read this: Reading IMSI in 3rd edition -Synchronously
    Nokia Developer Wiki Moderation team

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    Re: How print IMSI on emulator

    Quote Originally Posted by kiran10182 View Post
    I guess that you are working on S60 3rd edition. Check this: Reading IMSI in 3rd Edition

    For step by step representation, read this: Reading IMSI in 3rd edition -Synchronously
    Thanks for your reply. I have compiled the example but how you have specified it don't work on emulator. I tried to install example.SIS on my nokia n82 but show me : certificate error contact the application vendor...
    I have missing some step?
    Regards....missmè

  7. #7
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    Thanks for your reply. I have compiled the example but how you have specified it don't work on emulator. I tried to install example.SIS on my nokia n82 but show me : certificate error contact the application vendor...
    I have missing some step?
    Regards....missmè
    Emulator will give 000000... as IMSI. the certificate error you are getting as you have sign the application with proper capabilities.
    Last edited by skumar_rao; 2009-03-18 at 10:32.

  8. #8
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    Thanks for your reply. I have compiled the example but how you have specified it don't work on emulator. I tried to install example.SIS on my nokia n82 but show me : certificate error contact the application vendor...
    I have missing some step?
    Regards....missmè
    Simply put, IMSI comes from SIM card and Emulator does not have SIM card, you cannot retrieve IMSI on Emulator.

    As far as your installation error is concerned on N82, you have to sign your application with proper certificate. As you are fetching IMSI number through CTelephony class, you need ReadDeviceData capability which is an extended capability. Hence you need to sign your application with developer certificate. If you don't have Publisher Id then you can use OpenSigned Online option. https://www.symbiansigned.com/app/pa...ignedOnline.do

    First of all make sure that you include ReadDeviceData in your .mmp file and rebuild your application. Then sign it from OpenSigned Online option. Select ReadDeviceData capability on OpenSigned Online form.

    I hope that helps.
    Nokia Developer Wiki Moderation team

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    Re: How print IMSI on emulator

    Quote Originally Posted by skumar_rao View Post
    Emulator will give 000000... as IMEI. the certificate error you are getting as you have sign the application with proper capabilities.
    you could suggest me how to do?
    open signed of symbian?
    Sorry for my insistence and thanks more.

  10. #10
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    you could suggest me how to do?
    open signed of symbian?
    Sorry for my insistence and thanks more.
    Sorry but my reply was in simple English language also....
    Nokia Developer Wiki Moderation team

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    you could suggest me how to do?
    open signed of symbian?
    Sorry for my insistence and thanks more.
    I suggest you revisit the Getting started Guides for V9.x

  12. #12
    Registered User
    Join Date
    Jan 2009
    Posts
    6

    Re: How print IMSI on emulator

    Quote Originally Posted by kiran10182 View Post
    Sorry but my reply was in simple English language also....
    yes, your replay was in simple English language...but i'm very exhausted
    I have to sign my application?

  13. #13
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,345

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    yes, your replay was in simple English language...but i'm very exhausted
    I have to sign my application?
    Yes, as you are developing for S60 3rd edition platform, signing has become mandatory. Thus you have to sign your .sis file before installing on real device. Simply do what I suggested in my previous post.
    Nokia Developer Wiki Moderation team

  14. #14
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How print IMSI on emulator

    Quote Originally Posted by missmè View Post
    yes, your replay was in simple English language...but i'm very exhausted
    I have to sign my application?
    yes only Signed application can be installed on device.

Similar Threads

  1. Read from a text file
    By razas in forum Symbian
    Replies: 4
    Last Post: 2010-12-06, 05:53
  2. Launch Symbian EXE program with arguments
    By jend_rommel in forum Symbian
    Replies: 1
    Last Post: 2005-12-11, 21:37
  3. Replies: 0
    Last Post: 2004-05-21, 11:16
  4. Unable to save document to file?
    By yuva69 in forum Symbian
    Replies: 1
    Last Post: 2002-06-06, 13:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×