请参考经典:
http://mikie.iki.fi/symbian/autostart.html
下面内容就是链接地址的内容
Up to: Mika Raento's Symbian Programming pages
Symbian Programming - Starting applications automatically
3rd edition
On 3rd edition starting applications on device start is a supported feature of the platform, theStartup List.
1st/2nd edition
NOTE: although the instructions on this page work (for sufficiently narrow values of 'work'), they are suboptimal. Go grab our sources and look at autostart and starter code. The main difference is that you should wait until the PIN has been entered before starting your app.
Shaikh Shuja parvez rafiuddin wrote detailed instructions for using this code for your own application.
Note also that from 7.0 on (Series 60 version 2), you can use the Symbian Start-On-Boot API. You'll still have to code your own watchdog, though.
There seems to be only one way to autostart third-party applications on the Series 60 version 1: writing a recognizer. A recognizer is basically a dll (containing a class) meant to handle certain kinds of documents or files. We are not really interested in handling files, but recognizers are loaded at start up so we can embed code in one that starts the application(s) we want.
The basic requirements for a recognizer are:
- targettype MDL
- targetpath /system/recogs
- first uid 0x10003A19
- implement a class deriving from CApaDataRecognizerType
- implement GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
- implement EXPORT_C CApaDataRecognizerType* CreateRecognizer() that creates an instance of your class
Now you can put whatever code you want in CreateRecognizer(), for instance starting an app. As I understand it, this function is called in the context of some startup application, so you cannot block indefinitely. Instead the best way is to spawn another thread, return after that and have the new thread do the work.
In our project we actually use a watchdog that also restarts our application if it crashes. So we start the watchdog from the recognizer, and the watchdog starts the app.
Something to note is that it's not a good idea to start an application before the phone has booted completely, since not all services are yet available when the recognizers are loaded. Instead wait a while, it seems that 45 seconds is quite safe (a nicer way would probably be to wait until one of the system apps has started and start yours after that).
Example code
The example code is put in public domain: you may use it in any way you want.
Notable is also the structure of the watchdog. It is built as an EXEDLL, which means it's an exe for the phone and a dll for the emulator. It has the same first UID as an app. Now if we copy it to the emulator's /system/apps/starter as starter.app (note changing the extension) it can be started in the emulator by selecting it in the menu, so we can debug it. Of course starting it from the autostarter must be done differently depending on whether it's running on the phone or in the emulator. There is#ifdefed code that accomplishes this.
The EXEDLL must also implement two different entrypoints: EXPORT_C TInt InitEmulator() for the emulator and GLDEF_C TInt E32Main() for the actual phone. These must set up a CTrapCleanup before they can call any other Symbian code, and the code must be called within a TRAP.
================================
2nd 使用ezboot实现自启动的方法:(另转)
Symbian开机自动启动的问题:
一共分为两大步,每一大步里又分为几个小步骤:
一:创建boot文件
1:http://www.newlc.com/article.php3?id_article=152#nh1到这个网址下载适当版本的EzBoot
2:在.pkg文件目录下建一个新文件,命名为 项目名.boot
3: 在新建的 项目名.boot 文件里输入 boot:/system/apps/项目名/项目名.exe(或项目名.app,具体视开发内容而定)
4: 保存这个文件
二:编辑.pkg文件
1:在.pkg文件的末尾加上:"项目名.boot" -"!:/system/programs/ezboot/boot/项目名.boot"
2:最后别忘记加上:@"ezboot.sis",(0x101FD000)
然后利用makesis命令生成
这是它的英文描述:
EzBoot is a boot manager application. It allow you to autostart an application (typically a server) when the phone is powered on.
EzBoot is primarily targeted at application developers since it does not include any GUI application to let you configure the boot sequence [1]. Instead, the EZBoot package has been designed so that it can be integrated in another SIS package. By doing so and properly configuring a boot command file and your application's PKG file, you will be able to deploy "bootable packages" [2].
During the boot process, EzBoot will wait the sytem to complete the boot process and then launch each application it controls.
Note: EzBoot will not start any application if it finds a file called noboot in a directory /system/program/ezboot on any drive. This can be useful to prevent boot of unwanted/defective applications located on main phone memory.
We are using the following devices for the EzBoot development so the package is known to work on all of them:
Nokia N-Gage
Siemens SX1
Nokia 6600
SonyEricsson P900
Nokia 9300
Nokia 6680
However we are quite confident that it will work on any phones on market so far...
Latest Release : v0.6.4
Platform : Symbian OS 6.1 and upward
License : Free for non-commercial applications.
Author : Eric Bustarret
Homepage: http://www.newlc.com
Download :
How to use the EZBoot package
If you want to create your own bootable SIS package, you need to:
download and copy the ezboot.sis file to the directory where your PKG file is located
create a boot file. Ex for a <dummy> application:
open a text editor and create a file called <dummy>.boot
enter the path to your application (no need to specify the drive letter) [3]:
boot:/system/apps/<dummy>/<dummy>.exe
save the file in the directory where your PKG file is located.
edit your PKG file:
at the end, add the following line [4]:
"<dummy>.boot" -"!:/system/programs/ezboot/boot/<dummy>.boot"
and then, add the following line:
@"ezboot.sis",(0x101FD000)
===================================
3rd 实现中文说明-(另转)
在3版中实现并动态配置开机自启动
From Forum Nokia Wiki
适用版本:
Serire 60 3rd Edition
具体方案:在3版中使用了新的Startup List Management API实现开机自启动。需要应用程序实现开机自动启动,需要完成以下步骤: 1. 在项目的data目录下创建一个资源文件,名字为0xXXXXXX.rss, 0xXXXXXX为需要启动的程序的UID3。在资源文件中填入以下内容:
#include <startupitem.rh> RESOURCE STARTUP_ITEM_INFO startexe { executable_name = "//sys//bin//YourAppName.exe"; //换成你程序名字 recovery = EStartupItemExPolicyNone; }
2. 在你的项目文件.mmp中加入该资源文件
SOURCEPATH ../data START RESOURCE 0xXXXXXX.rss END
3.更新你的打包PKG文件,注意,该资源文件只能安装在C盘,不要忘记中括号:
“/epoc32/data/0xXXXXXX.rsc”- “c:/private/101f875a/import/[XXXXXX].rsc”
这样你的程序经过重新编译和打包,使用开发者证书签名以后就可以实现开机自启动了。
如果你希望在根据设置配置程序是否开机自启动,你还需要完成一下步骤: 1. 修改程序的注册资源文件YourAppName_reg.rss,添加如下代码
#include <appinfo.rh> #include <uikon.rh> RESOURCE APP_REGISTRATION_INFO { //原来的代码 opaque_data = r_startup_detect; } RESOURCE NUMBER_INT8 r_startup_detect {value = 1;}
2 重载AppUi中的ProcessCommandParametersL()函数
Bool CYourAppNameAppUi::ProcessCommandParametersL( CApaCommandLine &aCommandLine ) { if(aCommandLine.OpaqueData().Length() > 0) { // 此处为用户手动启动 } else { // 此处为程序开机后自动启动,如果设置为开机不自动启动, 在此处调用Exit()函数退出。 } return CEikAppUi::ProcessCommandParametersL( aCommandLine ); }