void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { StringBuilder message = new StringBuilder(); string relativeUri = string.Empty; Toast toast = new Toast(); if (e.Collection.ContainsKey("wp:Text1")) { toast.Title = e.Collection["wp:Text1"]; } if (e.Collection.ContainsKey("wp:Text2")) { toast.Subtitle = e.Collection["wp:Text2"]; } if (e.Collection.ContainsKey("wp:Param")) { toast.Param = e.Collection["wp:Param"]; } PluginResult result = new PluginResult(PluginResult.Status.OK, toast); Deployment.Current.Dispatcher.BeginInvoke(() => { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; if (frame != null) { PhoneApplicationPage page = frame.Content as PhoneApplicationPage; if (page != null) { CordovaView cView = page.FindName("CordovaView") as CordovaView; // was: PGView if (cView != null) { cView.Browser.Dispatcher.BeginInvoke((ThreadStart)delegate() { try { cView.Browser.InvokeScript("execScript", this.toastCallback + "(" + result.Message + ")"); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in InvokeScriptCallback :: " + ex.Message); } }); } } } }); }
void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) { System.Diagnostics.Debug.WriteLine("PushChannel_ShellToastNotificationReceived"); string title = string.Empty; string subtitle = string.Empty; string extras = string.Empty; e.Collection.TryGetValue("wp:Text1", out title); e.Collection.TryGetValue("wp:Text2", out subtitle); e.Collection.TryGetValue("wp:Param", out extras); Toast toast = new Toast(); toast.Title = title; toast.Subtitle = subtitle; toast.Extra = extras; if (IsRunningInBackground) { Microsoft.Phone.Shell.ShellToast ShellToast = new Microsoft.Phone.Shell.ShellToast(); ShellToast.Content = toast.Subtitle; ShellToast.Title = toast.Title; ShellToast.NavigationUri = new Uri(toast.Extra, UriKind.Relative); ShellToast.Show(); } else { PluginResult result = new PluginResult(PluginResult.Status.OK, toast); var script = new ScriptCallback(this.toastCallback, new string[] { result.Message }); this.InvokeCustomScript(script, false); } }