You Are Here:

Community: Wiki

This page was last modified on 20 September 2009, at 16:35.

Autostart applications on S60 2nd Edition phones

From Forum Nokia Wiki

Reviewer Approved   
"Danger, Will Robinson!"
Please note that the recognizer framework was not designed for the purpose of providing an autostart mechanism for 3rd party applications. It provides no fail-safe mechanism and will render the phone useless if an defective recognizer is installed. This is a hack and should be used only if the autostart feature is critical to your application and no other solutions is available for implementing it. In fact, Symbian provides the Start-On-Boot Registration API plug-in that enables the autostart feature for both the S60 2nd Edition and UIQ platforms.


Autostart applications in S60 2nd Edition phones. This is taken from mika raento's web-site,for information check this link.

Contents

In .mmp file

Create resource file (.mdl) to start application on bootup.

target CL_AUTOSTART.MDL
targettype MDL
targetpath \system\recogs\
uid 0x10003A19 0x09A770B5
SOURCEPATH ..\src
SOURCE cl_autostart.cpp
LANG SC
USERINCLUDE . ..\inc
SYSTEMINCLUDE . \epoc32\include \epoc32\include\libc
library EUSER.LIB APMIME.LIB efsrv.lib apparc.lib apgrfx.lib
LIBRARY efile.lib

Header File

#if !defined(__CL_AUTOSTART_H__)
#define __CL_AUTOSTART_H__
 
#if !defined(__APMREC_H__)
#include <apmrec.h>
#endif
 
#include <apgcli.h>
#include <f32file.h>
#include <apacmdln.h>
#include <e32std.h>
#include <apmstd.h>
 
 
class CclAutostart : public CApaDataRecognizerType
{
public: // from CApaDataRecognizerType
CclAutostart();
TUint PreferredBufSize();
TDataType SupportedDataTypeL(TInt aIndex) const;
static void StartThread();
static TInt StartAppThreadFunction(TAny* aParam);
static void StartAppThreadFunctionL();
 
private: // from CApaDataRecognizerType
void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
};
 
#endif

In .cpp File

We need to write a recognizer to autostart third-party applications on the Series 60 version 1. A recognizer is basically a dll (containing a class) meant to handle certain kinds of documents or files. Recognizers are loaded at start up so we can put code in one that starts the application(s) we want.

#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*/)
{
// this function is never called
}
 
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 ...
TRequestStatus timerStatus; // ... its associated request status
timer.CreateLocal(); // Always created for this thread.
// get current time (microseconds since 0AD nominal Gregorian)
TTime time;
time.HomeTime();
// add ten seconds to the time
TTimeIntervalSeconds timeIntervalSeconds(45);
time += timeIntervalSeconds;
// issue and wait
timer.At(timerStatus,time);
User::WaitForRequest(timerStatus);
 
 
// create a TRAP cleanup
CTrapCleanup * cleanup = CTrapCleanup::New();
TInt err;
if( cleanup === NULL )
{
err = KErrNoMemory;
}
else
{
TRAP( err, StartAppThreadFunctionL() );
}
delete cleanup;
 
 
 
 
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, ""); // dummy
 
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\\starter.app");
 
RProcess server;
 
 
 
CleanupClosePushL(server);
 
User::LeaveIfError(server.Create(fnAppPath, _L("")));
 
server.Resume();
 
 
 
CleanupStack::PopAndDestroy();
 
#endif
 
}
 
some devices above fun wont work use below code for 2nd edition devices eg:6600
 
void CclAutostart::StartAppThreadFunctionL()
{
// absolute file path to our application
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) );
CleanupStack::PopAndDestroy(3); // Destroy fsSession, ls and cmdLine
}
 
 
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;
}

In .Pkg file

Attach .mdl file to package.

"cl_autostart.mdl"         -"!:\system\recogs\cl_autostart.mdl"

Tips

  • It is always recommended that the time interval to autostart the app should be equal to or more than 10 seconds. This is because in slower phones for e.g. Nokia 6600 or Nokia 3230 the boot process after loading a number of applications becomes very slow. If the autostart application is to load during this time the boot becomes much slower.
  • The above code starts the application on phone boot up and the application remains in the foreground. The application staying in the foreground may not be the actual behavior as wanted. You may want that the application should autostart and stay in the background. This can be achieved for e.g. by using some flag file, but the launch cannot be hidden. The application will come in the foreground and then go to the background.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTalkE3aE4cargeE5fscreenE5fsaverX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx4E2E0000X