Beispiel #1
0
 /// <summary>
 /// 启动默认的app
 /// </summary>
 /// <param name="startParams">启动参数</param>
 public void StartDefaultApp(XStartParams startParams)
 {
     XWebApplication defaultApp = (XWebApplication)this.GetAppList().GetAppById(GetDefaultAppId());
     if (defaultApp == null)
     {
         XToastPrompt.GetInstance().Toast(xFaceLibResources.Start_DefaultApp_Error);
         return;
     }
     defaultApp.IsDefaultApp = true;
     //TODO 注册AMS 扩展
     var amsExt = WPCordovaClassLib.Cordova.CommandFactory.CreateByServiceName("AMS");
     if (amsExt != null)
     {
         amsExt.InvokeMethodNamed("init", this);
     }
     ;
     if (AMS_ERROR.ERROR_BASE != StartApp(defaultApp.AppInfo.AppId, startParams))
     {
         XToastPrompt.GetInstance().Toast(xFaceLibResources.Start_DefaultApp_Error);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 启动app应用
        /// </summary>
        /// <param name="appId">应用id</param>
        /// <param name="appparams">应用参数</param>
        /// <returns>启动应用的错误码</returns>
        public AMS_ERROR StartApp(String appId, XStartParams appparams)
        {
            XApplication app = this.GetAppList().GetAppById(appId);
            if (null == app)
            {
                XLog.WriteError("failed to startapp! can't find app by id:" + appId);
                return AMS_ERROR.APP_NOT_FOUND;
            }

            if (!IsValidAppEntry(app.AppInfo.Entry))
            {
                XLog.WriteError("failed to startapp! app entry can't be NullOrEmpty by id:" + appId);
                return AMS_ERROR.APP_ENTRY_ERR;
            }

            String startData = null;
            if (null != appparams)
            {
                startData = appparams.Data;
            }

            //TODO: 对于active app是否应该bringtoTop
            if (app is XNativeApplication)
            {
                //FIXME: 对于启动nativeApp 成功与否系统会做出提示
                app.Load();
            }
            else
            {
                if (!app.IsActive())
                {
                    activeApps.Add(app);
                    //注册close 和 sendMessage的event监听
                    EventHandler<string> AppCloseHandler = delegate(object o, string id)
                    {
                        CloseApp(id);
                    };
                    ((XWebApplication)app).AppClose += AppCloseHandler;

                    EventHandler<string> AppSendMsgHandler = delegate(object o, string id)
                    {
                        HandleAppEvent((XApplication)o, kAppEventMessage, id);
                    };
                    ((XWebApplication)app).AppSendMessage += AppSendMsgHandler;

                    String pageEntry = null;
                    if (null != appparams)
                    {
                        pageEntry = appparams.PageEntry;
                    }
                    if (pageEntry != null && pageEntry != string.Empty)
                    {
                        app.AppInfo.Entry = pageEntry;
                        if (IsValidAppEntry(app.AppInfo.Entry))
                        {
                            XLog.WriteError("failed to startapp! app entry can't be NullOrEmpty by id:" + appId);
                            return AMS_ERROR.APP_ENTRY_ERR;
                        }
                    }
                    if (startData != null)
                    {
                        ((XWebApplication)app).SetData(XConstant.TAG_APP_START_PARAMS, startData);
                    }
                    this.amsDelegate.StartApp((XWebApplication)app);
                }
                else
                {
                    XLog.WriteError("failed to startapp! app already running by id:" + appId);
                    return AMS_ERROR.APP_ALREADY_RUNNING;
                }
            }
            //没错误
            return AMS_ERROR.ERROR_BASE;
        }