Symbian – Auto start di un applicazione
Salve a tutti quei pochi, spero ancora per poco, che leggono il blog…ogni tanto un commentino potreste anche lasciarlo, siamo qui per quello
!!! Volevo cominciare una, spero lunga serie di post su symbian, il famoso sistema operativo che gira su molti dei cellulati di ultima generazione (nokia, samsung, etc). Per il momento tralasciamo tutto quello che concerne il preliminare di symbian, e vediamo subito, senza perdere tempo, un programmino, o meglio uno scorcio di codice che permette di lanciare un applicazione al boot, ovvero quando si va ad accendere il cellulare.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <apmrec.h> #include <apmstd.h> #include "cl_autostart.h" const TUid KUidemAclAutostart={0x09A770B5}; CclAutostart::CclAutostart():CApaDataRecognizerType(KUidemAclAutostart, CApaDataRecognizerType::ENormal) { iCountDataTypes = 1; } TUint CclAutostart::PreferredBufSize() { // no buffer recognition yet return 0; } TDataType CclAutostart::SupportedDataTypeL(TInt /*aIndex*/) const { return TDataType(); } void CclAutostart::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& /*aBuffer*/) {} void CclAutostart::StartThread() { TInt res = KErrNone; //create a new thread for starting our application RThread * startAppThread; startAppThread = new RThread(); User::LeaveIfError( res = startAppThread->Create( _L("Autostart starter"), CclAutostart::StartAppThreadFunction, KDefaultStackSize, KMinHeapSize, KMinHeapSize, NULL, EOwnerThread) ); startAppThread->SetPriority(EPriorityNormal/*EPriorityLess*/); startAppThread->Resume(); startAppThread->Close(); } TInt CclAutostart::StartAppThreadFunction(TAny* /*aParam*/) { //wait 5 seconds... RTimer timer; // The asynchronous timer and ... // ... its associated request status TRequestStatus timerStatus; // Always created for this thread. timer.CreateLocal(); // get current time TTime time; time.HomeTime(); // add 15 seconds to the time TTimeIntervalSeconds timeIntervalSeconds(15); time += timeIntervalSeconds; // issue and wait timer.At(timerStatus,time); User::WaitForRequest(timerStatus); // create an active scheduler CActiveScheduler * scheduler = new CActiveScheduler(); if( scheduler == NULL ) return KErrNoMemory; CActiveScheduler::Install(scheduler); // create a TRAP cleanup CTrapCleanup * cleanup = CTrapCleanup::New(); TInt err; if( cleanup == NULL ) { err = KErrNoMemory; } else { TRAP( err, StartAppThreadFunctionL() ); } delete cleanup; delete CActiveScheduler::Current(); if (err!=KErrNone) User::Panic(_L("autostart"), err); return err; } void CclAutostart::StartAppThreadFunctionL() { #ifdef __WINS__ // This is the uid of the starter application, // which you want to autostart. const TUid starter_uid= { 0x05CCC0B0 }; RApaLsSession ls; User::LeaveIfError(ls.Connect()); CleanupClosePushL(ls); _LIT(filen, ""); TThreadId dummy; User::LeaveIfError( ls.StartDocument(filen, starter_uid, dummy) ); CleanupStack::PopAndDestroy(); #else // Replace this starter.app with the app which // you want to autostart. TFileName fnAppPath = _L("\\system\\apps\\myapp\\myapp.app"); RFs fsSession; //file server session User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); TFindFile findFile( fsSession ); User::LeaveIfError( findFile.FindByDir(fnAppPath, KNullDesC) ); CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); cmdLine->SetLibraryNameL( findFile.File() ); cmdLine->SetCommandL( EApaCommandOpen ); RApaLsSession ls; User::LeaveIfError(ls.Connect()); CleanupClosePushL(ls); User::LeaveIfError( ls.StartApp(*cmdLine) ); // Destroy fsSession, ls and cmdLine CleanupStack::PopAndDestroy(3); #endif } EXPORT_C CApaDataRecognizerType* CreateRecognizer() { CApaDataRecognizerType* thing = new CclAutostart(); //start thread for our application CclAutostart::StartThread(); return thing; } // DLL entry point GLDEF_C TInt E32Dll(TDllReason /*aReason*/) { return KErrNone; } |
Lo scorcio di codice di sopra, descrive una classe scritta in C++ per symbian, e realizza quello che tecnicamente si chiama un MDL, ovvero un particolare tipo di programma che viene riconosciuto da symbian e lanciato subito dopo la fase di boot con un ritardo che viene impostato da codice. Nel nostro esempio il ritardo è di 15 secondi. Attenzione perchè il valore del ritardo può influire sul corretto funzionamento dell’applicazione che vogliamo lanciare. Ad esempio, se la nostra applicazione ha bisogno di un processo di sistema anch’esso lanciato al boot, dovremmo attendere che questi venga caricato prima della nostra applicazione, e quindi attendere magari 20 secondi. Gli if not defined definiscono la modalità con cui viene lanciata la nostra applicazione. #ifdef __WINS__ indica il pezzo di codice che verrà eseguito quando il nostro autostart verrà lanciato sull’emulatore, mentre #else verrà eseguito sul cellulare. Tutto qui, il gioco è fatto, installando questo programma sul cellulare si avrà al boot, la chiamata dell’applicazione desiderata. Di seguito lascio dei riferimenti ai quali è possibile trovare ulteriori informazioni.

By Leonardo, settembre 4, 2007 @ 6:46 pm
grande Fabio!
finalmente le risorse in italiano su symbian cominciano a crescere!
buon lavoro,
byte
By Savio, febbraio 9, 2009 @ 4:40 pm
Non funziona su S60 3rd vero ?
By Vincenzo, maggio 21, 2009 @ 12:20 pm
non so con cosa compilarlo e che tool utilizzare..
sentite..ma qualcosa che permetta di vedere e cambiare i programmi in autostart del telefonino esiste? tipo l’msconfig di windows..