通过Application安装widget

来源:互联网 发布:取法乎上得乎其中原句 编辑:程序博客网 时间:2024/05/16 04:45

    LOG_BEGIN("Install the widget");

    CActiveScheduler* activeScheduler = new CActiveScheduler();
    CActiveScheduler::Install( activeScheduler );

    RWsSession wsSession;
    User::LeaveIfError( wsSession.Connect() );
    TApaTaskList taskList( wsSession );
    const TUid KInstallerUid = {0x101f875a};

   
    while( taskList.FindApp( KInstallerUid ).Exists() )
    {
        LOG_WRITE("waiting install to finish");
        User::After( TTimeIntervalMicroSeconds32( 1000000 ) );
    }

    RApaLsSession lsSession;
    User::LeaveIfError( lsSession.Connect() );
    CleanupClosePushL( lsSession );//+lsSession
   
    TFileName widgetName;
    widgetName.Copy( RProcess().FileName().Left( 2 ) );
    widgetName.Append( _L( "//system//data//mywidget.wgt" ) );

    TThreadId id;
    TInt err = lsSession.StartDocument( widgetName, id );
    LOG_FORMAT2( _L("start the widget: %S (%d)"), &widgetName, err );

    User::After( TTimeIntervalMicroSeconds32( 2000000 ) );
    CleanupStack::PopAndDestroy();

    delete activeScheduler;

    LOG_END("Install the widget");