Autostart your application on phone boot

来源:百度文库 编辑:神马文学网 时间:2024/04/29 15:54:01
There are several ways to autostart your application at phone boot. Unfortunately, none of them is universal and you will have to use at least two of the four APIs described in this tutorial: the recognizer, the Symbian "Start-On-Boot" API, the Nokia Startup List API and the SonyEricsson AutoStarter API.
Recognizers are the usual way of autostarting an application on devices based on S60 1st and 2nd edition and UIQ v2. This is however not their primary purpose, as they are part of the content handling framework.
 
Writing a recognizer is fairly easy and documented. As an example, you can get ourown source code taken out of a more packaged boot utility calledEzBoot.
You must be aware that, while the code is rather simple, a badly written recognizer can totally lock a device unless you know the "disable recognizer shortcut" (boot the phone while pressing the pencil key on S60 phones). Recognizer are started quite early during the phone boot process and some service might not be available when your application is started. As an example, your application will be started before the user has entered its PIN code. Which mean that you won‘t be able to access the network or most of the SIM and user data unless you write your own waiting mechanism (note that EZBoot does that for you and ensure that the phone has completely started before lauching your application). Recognizers can‘t be used anymore to boot an application on S60 3rd Edition FP1.
 
The SymbianStart-On-Boot is a recognizer packaged by Symbian Ltd. This API is compatible with all version of Symbian OS from 6.1 to 8.0a (and thus the S60 v1,v2 and UIQ v2 platforms).
 
The package contains SIS file, binaries and header file so that you can use it in a test environment or integrate it into your application.
Registering an exe with this service mainly consist in calling the RServiceStartOnBoot::AddServiceL() primitive giving the full path to your exe file:
 
RServiceStartOnBoot sob;sob.CreateL();CleanupClosePushL(sob);sob.AddServiceL(_L("\\\\programToStart.exe"));CleanupStack::PopAndDestroy();
 
Add the following line at the end of your PKG file (here assuming that you are working with S60 v2 target and that the SIS file containing the API is in the same directory as your pkg file):
 
@"exestartonboot_s60v2_0_SymbianSigned.sis",(0x????)
 
The value of ???? must reflect the UID of the SIS file.
Here are a few important points:
The service will be started approximatively 1 minute after the phone has started. The service will be automatically removed from the start service if the phone reboots within 3 minutes of the startup following the installation of the service (or if the user do reboot his phone). Only EXE files (thus no application) can be started using this API
 
The Startup List API has been introduced in S60 3rd Edition and is the standard way to start your application on these devices. The advantage of this API is that this is a standard and documented API which is now part of the S60 platform. No dirty trick inside.
 
Here is how to use it.
The first step is to create a specific resource file that will contain the boot information. You have not many option in this file. Call it yyyy.rss where yyyy is the UID3 of the executable to start:
 
#include RESOURCE STARTUP_ITEM_INFO startexe{executable_name = "\\sys\\bin\\programToStart.exe";recovery = EStartupItemExPolicyNone;}
 
You are not dumb so replace the name programToStart.exe by the name of your executable file. You currently don‘t have any other option as the executable must reside in the \sys\bin\ directory and the recovery parameter cannot take any other value than the one described (this is valid up to S60 FP1 and future version may introduce further values).
I usually write this file in a Data directory where resides all my other resource files. Put you can put it wherever you want. The Group directory is another good option if you prefer.
The resource file described above shall now be added to the compilation process. To do so, you have to update your MMP file with the lines below:
SOURCEPATH ..\dataSTART RESOURCE yyyy.rssEND
 
The SOURCEPATH line contain the relative or absolute path to the rss file. At this point, user of Nokia Codewarrior will have to reimport their project so that the change in the MMP file is correctly taken into account.
And finally you also have to edit your PKG file so that the compiled boot resource is written on device:
 
"\epoc32\data\yyyy.rsc"- "c:\private\101f875a\import\[yyyy].rsc"
 
Also check that the UID3 of the package must match the yyyy value:
#{"My Application Name"},(0xyyyy),1,00,0
 
Some important points here:
the resource file is compiled as yyyy.rsc (or yyyy.r01,yyyy.r02,etc...) for a multilingual application and must be installed with additional square brackets in its name, here [yyyy].rsc. the resource file must be installed on the c: drive, no matter where your application is located. If not, it will be ignored during the boot sequence. the application must be signed with a valid developer certificate (or Symbian Signed). Applications signed with a self generated certificate cannot use this API. the started executable must run for at least 6 seconds or a warning message will be shown to the user: Unable to start programToStart.exe. Application may need to be removed.
Note that the second point is an acceptable exception to the Symbian Signed test criteria PKG-03 ("File Creation Location"), see EX-006 ("Small Files for Maintaining Configuration and Settings Information, or which the System creates").
 
The SonyEricsson Application Startup API is not documented anywhere - or at least I did not found any official descriptive information about it, just thisthread on our forums.
 
This is however a working trick to have your application auto-started on SonyEricsson phones - at least those running UIQ 3.0 platform. I have no information whether this will be supported by the upcoming Motorola UIQ based phones nor any future phone.
This API is relatively simple to use. First, create a text file, named programToStart.ast, containing the name of the executable to start, with no path information:
 
programToStart.exe
 
Then update your pkg file with the following line at its end:
 
"..\data\programToStart.ast"-"!:\private\10274b9f\import\programToStart.ast"
 
The AST file must be made of a single line with just the executable name and no CR/LF at its end. Your application must have the WriteUserData capability Unlike other methods, this API won‘t start your exe directly after installation.
 
EzBoot and itsrecognizer source code.Symbian Start-On-Boot APIStartup List Reference Documentation