怎样实现 Symbian 应用程序开机自启动
1.在 data目录下创建一个资源文件,名字为 xxx.rss, 其中 xxx为任意符合编码规范的文件名均可。
例如, mylauncher.rss ,该资源文件内容如下所示:
#include <startupitem.rh>
RESOURCE STARTUP_ITEM_INFO startexe
{
executable_name = "c://sys//bin//TestLauncher_0xE8028B2A.exe" ;
//or "!://sys//bin//TestLauncher_0xE8028B2A.exe", TestLauncher_0xE8028B2A.exe is your app name
recovery = EStartupItemExPolicyNone;
}
2. 更新 MMP文件
START RESOURCE mylauncher.rss
TARGET mylauncher.rsc
END
3. 更新 PKG文件
在 pkg文件里面添加如下内容:
"C:/S60/devices/Nokia_N97_SDK_v1.0/epoc32/data/mylauncher.rsc " -"c:/private/101f875a/import/[E8028B2A ].rsc"
, 其中 mylauncher.rsc 为你先前新建的资源文件名, E8028B2A 为应用程序的 uid3, 可以在 mmp 中查看。必须有中括号 [ ].
注意: 该 sis 文件必须装在 c 盘,必须用开发者 证书签名。
如果你要设置是否开机自启动(如可以通过判断某文件是否存在来决定该程序是否在随机启动), 则需要继续执行下面的步骤:
4. 修改 ***_reg.rss 文件, 如这里的 TestLauncher_reg.rss,修改后的 TestLauncher_reg.rss文件如下:
…(原文)
#include <uikon.rh>
… (原文)
RESOURCE APP_REGISTRATION_INFO
{
…( 原文 )
opaque_data = r_startup_detect;
}
RESOURCE NUMBER_INT8 r_startup_detect
{
value = 1;
}
5. 在 ***AppUi.h 和 ***AppUi.cpp 中实现 ProcessCommandParametersL
如这里的: TestLauncherAppUi.h:
class CTestLauncherAppUi : public CAknAppUi
{
…
public :
// Inherit from CEikAppUi, for autostart.
TBool ProcessCommandParametersL (CApaCommandLine &aCommandLine);
…
}
TestLauncherAppUi.cpp:
TBool CTestLauncherAppUi::ProcessCommandParametersL (CApaCommandLine &aCommandLine)
{
#ifndef __WINS__
if (aCommandLine.OpaqueData().Length() > 0)
{
RDebug::Print(_L("CScpAutoStarter<=ApplicationStartsL 1 "));
// Opaque data exists, app. has been manually started from the menu
}
else
{
// App. has been auto-started -> exit if auto-start in settings is OFF
TBool autoStart = ETrue;
// we can change the bool variable autoStart under some conditions,
// such as if the file is not exist, we can set autoStart to EFalse.
if ( !autoStart )
{
User::Exit(0);
}
else
{
// Send the app to the background, after it was started up
}
}
return CEikAppUi::ProcessCommandParametersL( aCommandLine );
#endif
}