navigator.app.exitApp() is not working

后端 未结 7 1028
予麋鹿
予麋鹿 2021-01-05 14:36

I am developing Windows phone 8 PhoneGap app. Using navigator.app.exitApp() I am quiting the app from home screen in Windows phone 7. But when I tried the same in Windows ph

相关标签:
7条回答
  • 2021-01-05 15:12

    I develop small application for Windows Phone 8.1 and the code below works for me:

    window.close();
    
    0 讨论(0)
  • 2021-01-05 15:14

    Similar question here: How to exit an application in window phone 8 with phonegap 2.3 includes a fix that doesn't require any native hacking.

    0 讨论(0)
  • 2021-01-05 15:23

    In version 3.6.3, navigator.app.exitApp() does work.

    Here is where it is called in CordovaView.cs

    void CordovaBrowser_ScriptNotify(object sender, NotifyEventArgs e)
    {
        string commandStr = e.Value;
    
        string commandName = commandStr.Split('/').FirstOrDefault();
    
        if (browserDecorators.ContainsKey(commandName))
        {
            browserDecorators[commandName].HandleCommand(commandStr);
            return;
        }
    
        CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr);
    
        if (commandCallParams == null)
        {
            // ERROR
            Debug.WriteLine("ScriptNotify :: " + commandStr);
        }
        else if (commandCallParams.Service == "CoreEvents")
        {
            switch (commandCallParams.Action.ToLower())
            {
                case "overridebackbutton":
                    string arg0 = JsonHelper.Deserialize<string[]>(commandCallParams.Args)[0];
                    this.OverrideBackButton = (arg0 != null && arg0.Length > 0 && arg0.ToLower() == "true");
                    break;
                case "__exitapp":
                    Debug.WriteLine("Received exitApp command from javascript, app will now exit.");
                    CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" });
                    CordovaBrowser.InvokeScript("eval", new string[] { "setTimeout(function(){ cordova.fireDocumentEvent('exit'); cordova.exec(null,null,'CoreEvents','__finalexit',[]); },0);" });
                    break;
                case "__finalexit":
                    IsExiting = true;
                    // hide the browser to prevent white flashes, since about:blank seems to always be white
                    CordovaBrowser.Opacity = 0d; 
                    CordovaBrowser.Navigate(new Uri("about:blank", UriKind.Absolute));
                    break;
            }
        }
        else
        {
            if (configHandler.IsPluginAllowed(commandCallParams.Service))
            {
                commandCallParams.Namespace = configHandler.GetNamespaceForCommand(commandCallParams.Service);
                nativeExecution.ProcessCommand(commandCallParams);
            }
            else
            {
                Debug.WriteLine("Error::Plugin not allowed in config.xml. " + commandCallParams.Service);
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-05 15:23

    navigator.app.exitApp(); has been available in Apache Cordova WP8 projects since 3.4.0

    <div onclick="navigator.app.exitApp()">Exodus</div>
    
    0 讨论(0)
  • 2021-01-05 15:28

    You can create a simple plugin. Add file ExitApp.css to your platforms/wp8/Plugins folder with:

    using System.Windows;
    
    namespace WPCordovaClassLib.Cordova.Commands
    {
      class ExitApp : BaseCommand
      {
        public void execute(string options)
        {
            Application.Current.Terminate();                        
        }
      }
    }
    

    edit your platforms/wp8/config.xml and add to the widget tag:

    <feature name="ExitApp">
      <param name="wp-package" value="ExitApp" />
    </feature>`
    

    then from you javascript call:

    cordova.exec(null, null, "ExitApp", "execute", []);
    

    You can use it in combination with backbutton event to close the app when the user clicks on backbutton in the main page:

    function goBack(e){
      if(isInMyMainPage()) cordova.exec(null, null, "ExitApp", "execute", []);
    }
    document.addEventListener("backbutton", goBack, false)
    
    0 讨论(0)
  • 2021-01-05 15:30

    Similar question here: https://groups.google.com/forum/#!msg/phonegap/9v2kOwXj6sQ/O8SVpd-qjicJ

    But it basically says that windows phone 8 apps shouldn't be programatically exited.

    0 讨论(0)
提交回复
热议问题