Symbian 3rd 带参数启动进程

Symbian 3rd 带参数启动进程

Author: cding
Time: 11:15 2007-6-7

S60v2带参数的调用比较简单,通过openfile等模式就可以得到buf8 or filename的参数,最新的S60 3rd/UIQ3.1由于加入了安全性检查,使得打开文件方式的调用都被拦截,在加入SWEvent的能力后才能使用:
MMP里加入:
CAPABILITY    SWEvent

测试代码:
1. StartApp 方式调用:
    CApaCommandLine *cmd=CApaCommandLine::NewLC();
    cmd->SetCommandL(EApaCommandRun);
    cmd->SetExecutableNameL(_L("HelloWorld.exe"));
    cmd->SetDocumentNameL(_L("x.txt"));
    RApaLsSession als;
    User::LeaveIfError(als.Connect());
    CleanupClosePushL(als);
    User::LeaveIfError(als.StartApp(*cmd));
    CleanupStack::PopAndDestroy(2);

2. StartDocument
    RApaLsSession als;
    TThreadId id;
    TUid uid;
    uid.iUid = 0xE0001001;
    als.Connect();
    als.StartDocument(_L("yourdocument.txt"), uid, id);
    als.Close();

3. PProcess
    RProcess* process = new RProcess();
    TUidType uidtype(KNullUid);
    process->Create(_L("//sys//bin//HelloWorld.exe"), _L("teststring"), uidtype);
    process->Resume();
    process->Close();
    delete process;

4. TFindProcess

 _LIT(KPROCESSNAME, "SMSHanger*");
 TFullName processName;
 TFindProcess findProcess(KPROCESSNAME);
 findProcess.Next(processName);
 if (processName == KNullDesC)
 {
  __LOG("YYYY The test 005!/n");

  // if SMSHanger is not running, start it!
  RApaLsSession session;
  User::LeaveIfError(session.Connect());
  CleanupClosePushL(session);
  CApaCommandLine* cmdln = CApaCommandLine::NewLC();
  cmdln->SetExecutableNameL(_L("SMSHanger.exe"));
  cmdln->SetCommandL(EApaCommandRun);
  User::LeaveIfError(session.StartApp(*cmdln));
  CleanupStack::PopAndDestroy(2);

  __LOG("YYYY The task is start!/n");
 }

在完成启动后可以通过task来检查并激活进程:
    TUid uidApp = TUid::Uid(0xE0001001);
    TApaTaskList taskList(CEikonEnv::Static()->WsSession());
    TApaTask task = taskList.FindApp(uidApp);
    TBuf<256> arg;
    arg.Append(_L("yourteststring"));
    HBufC8* pBuf;
    if(task.Exists())
    {
        //send message to the task; uid is not used, but it doesn's work.
        pBuf = HBufC8::NewL(arg.Length());
        TPtr8 ptr = pBuf->Des();
        ptr.Copy(arg);
        nErr = task.SendMessage(TUid::Uid( KUidApaMessageSwitchCreateFileValue ), *pBuf);
        nErr = task.SwitchOpenFile(arg);
        task.BringToForeground();
    }
这个在软件开发期间是能工作的,但作为产品,最终还是必须要做SymbianSign才能通过,详细的可以看本站SymbianSign的帖。

你可能感兴趣的:(session,user,cmd,测试,delete,Symbian)