Subject: [技巧] 如何判断程序是否被自动启动或者被用户启动
Lee
Administrator
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 0
Credits 18567
Posts 133
Money 189
Reading Access 200
Registered 13-3-2007
Status Offline
Post at 13-3-2007 15:25  Profile | Blog | P.M. 
如何判断程序是否被自动启动或者被用户启动

有时候能够检查出在系统启动的时候哪些应用程序被“Startup List Api(只有S60 3rd可以使用)”或者用户启动,和通过“Symbian Signed”,管理启动程序的应用是一个很通用的程序,这篇文章将告诉你如何做到。

首先,你必须修改程序注册文件,并在APP_REGISTRATION_INFO资源中添加一些opaque_data字段,内容和直并不是那么重要,你只需要按下面的方式指定:

#include <appinfo.rh>
#include <uikon.rh>   

RESOURCE APP_REGISTRATION_INFO
{
  ...
  opaque_data = r_startup_detect;
}      

   
RESOURCE NUMBER_INT8 r_startup_detect
{
value = 1;
}

当应用程序运行时,opaque_data和其他运行参数将被忽略。因此,判断是否在运行或者不允许(区分是否应用程序被允许在启动的时候或者被用户启动)。

这样,你可以重载AppUI中的ProcessCommandParametersL()函数
T

Bool CMyAppUi::ProcessCommandParametersL( CApaCommandLine &aCommandLine )
{
  if(aCommandLine.OpaqueData().Length() > 0)
  {
      // 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
  }
   return CEikAppUi::ProcessCommandParametersL( aCommandLine );
}

你也要注意,通过Symbian Signed需要你的应用程序有一个允许禁止自动启动的属性的选项设置。你需要加入操作代码来实现它,在 Forum Nokia Technical Library中描叙得比较好。

这篇文章仅适用于 S60 3RD,接下来的版本也将支持这个属性




有其他问题请加入Symbian开发群参与讨论:群 ①:623041已满,群②:36865776已满 请加群③:76404484
Top
Lee
Administrator
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 0
Credits 18567
Posts 133
Money 189
Reading Access 200
Registered 13-3-2007
Status Offline
Post at 13-3-2007 15:28  Profile | Blog | P.M. 
How to detect if an application is launched by user or the startup list

It is sometimes useful to be able to detect whether an application is started at boot time by the Startup List API (present only in S60 3rd Edition) or by the user, and passing Symbian Signed - which is generally required to have an application which requires auto boot feature - makes this almost mandatory. This article will help you with this.

First, you have to modify the application registration file and add some opaque_data field in the APP_REGISTRATION_INFO resource. The content and value of these data does not really matter, you just need to specify something like below:

#include <appinfo.rh>
#include <uikon.rh>   

RESOURCE APP_REGISTRATION_INFO
{
  ...
  opaque_data = r_startup_detect;
}      

   
RESOURCE NUMBER_INT8 r_startup_detect
{
value = 1;
}

The opaque_data and other launch parameters will be ignored by the startup list when launching the application. Thus, detecting whether they are present or not allows to differentiate whether the application has been launched at boot time or by the user.

To do this, you shall override the ProcessCommandParametersL() function in your AppUI:

TBool CMyAppUi::ProcessCommandParametersL( CApaCommandLine &aCommandLine )
{
  if(aCommandLine.OpaqueData().Length() > 0)
  {
      // 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
  }
   return CEikAppUi::ProcessCommandParametersL( aCommandLine );
}

you can also note that passing Symbian Signed requires that your application has a setting option that allow to disable the auto start feature. As no API is currently available to do this, you will need to have some code to handle this. Hopefully, this is very well explained in the Forum Nokia Technical Library (which this article is based on).

This article only applies to S60 3rd Edition and following versions which implements the Startup List API.

原文地址




有其他问题请加入Symbian开发群参与讨论:群 ①:623041已满,群②:36865776已满 请加群③:76404484
Top
 


All times are GMT+8, the time now is 5-9-2010 14:43

CopyRight © Symbianx.cn 2007 Powered By Discuz! 5
Clear Cookies - Contact Us - Symbian OS系统[S60,UIQ]开发中文翻译论坛 - Archiver

本站原文版权归原文作者所有,本站译文版权归本站所有,如需转载请注明原文和译文出处,否则追究法律责任