How to set push notification receive message target page in windows phone?

999 Views Asked by At

I need to set push notification receive message target page in windows phone. I can send and receive toast push notifications, but when I am click the received toast message it goes to the main page. When I click the toast message I need the app to open in the target page. Please let me know why I am facing in this issue and what is wrong in my code.

My code is given below:

C# Receive Target page:

 void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
    {
        StringBuilder message = new StringBuilder();
        string relativeUri = string.Empty;

        message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

        // Parse out the information that was part of the message.
        foreach (string key in e.Collection.Keys)
        {
            message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

            if (string.Compare(
                key,
                "wp:Param",
                System.Globalization.CultureInfo.InvariantCulture,
                System.Globalization.CompareOptions.IgnoreCase) == 0)
            {
                relativeUri = e.Collection[key];

            }
        }

        // Display a dialog of all the fields in the toast.
        Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString()));

    }
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        //  If we navigated to this page
        // from the MainPage, the DefaultTitle parameter will be "FromMain".  If we navigated here
        // when the secondary Tile was tapped, the parameter will be "FromTile".
        textBlockFrom.Text = "Navigated here from " + this.NavigationContext.QueryString["NavigatedFrom"];

    }

I am using PHP code for sending the push notifications:

  <?php 
  final class WindowsPhonePushDelay
  {

   const Immediate=0;

   private function __construct(){}
 }

 class WindowsPhonePushNotification
 {
  private $notif_url = '';

  function WindowsPhonePushNotification($notif_url)
  {
     $this->notif_url = $notif_url;
  }
  public function push($target,$message,$notif_url)
  {

   // Create the toast message
   $toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
            "<wp:Notification xmlns:wp=\"WPNotification\">" .
               "<wp:Toast>" .
                    "<wp:Text1>" . "SendToast" . "</wp:Text1>" .
                    "<wp:Text2>" . $message . "</wp:Text2>" .
                    "<wp:Param>/Receive.xaml?NavigatedFrom=Toast Notification</wp:Param>" .
                    "</wp:Toast> " .
            "</wp:Notification>";

  // Create request to send
     $r = curl_init();
     curl_setopt($r, CURLOPT_URL,$notif_url);
     curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($r, CURLOPT_POST, true);
     curl_setopt($r, CURLOPT_HEADER, true); 

  // add headers
     $httpHeaders=array('Content-type: text/xml; charset=utf-8', 'X-WindowsPhone-Target: toast',
                'Accept: application/*', 'X-NotificationClass: 2','Content-Length:'.strlen($toastMessage));
  curl_setopt($r, CURLOPT_HTTPHEADER, $httpHeaders);

  // add message
  curl_setopt($r, CURLOPT_POSTFIELDS, $toastMessage);

  // execute request
  $output = curl_exec($r);
  curl_close($r);

   }
}

?>

I need output as in the image below

enter image description here

1

There are 1 best solutions below

2
On

The wp:param that's part of the toast notification's payload should be a uri. Therefore it should also be encoded as one. In the example that you're providing there's a space in the payload, that might be causing problems. Could you try formatting it like this?

  "<wp:Param>/Receive.xaml?NavigatedFrom=Toast%20Notification</wp:Param>" .

Also make sure that Receive.xaml is indeed in the root of your package.