locked
Launch a new page on Clicking a push notification in Store app?

    Question

  • I am trying to launch an explicit page whenever user clicks on an push notification to demonstrate a concept.

    This code used to work earlier(last year) but i dont remember what i changed in the interim that it stopped working.

    Here is the code for app.xaml .

    private async void AcquirePushChannel()
         {
             try
             {
                 CurrentChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

             }
             catch (Exception)
             {
                 new MessageDialog("Cannot Contact Azure Server", "Operation Timed Out");

             }
             IMobileServiceTable<Registrations> registrationsTable = App.MobileService.GetTable<Registrations>();
             var registration = new Registrations { Handle = CurrentChannel.Uri };
             await registrationsTable.InsertAsync(registration);



         }




        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
        }

        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;


            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            string launchstring = args.Arguments;

            if (!string.IsNullOrEmpty(launchstring))
            {
                rootFrame.Navigate(typeof(InstructionSetBlue));
            }
                AcquirePushChannel();


            // Ensure the current window is active
         Window.Current.Activate();

        }

    I am trying to debug this but could not figure out the mistake in my code. Can anybody tell me where the issue might be .Thanks

    Friday, May 09, 2014 1:39 PM

Answers

  • Hi,

    The toast notification that you send needs to have the "launch" attribute defined and the toast template would look something like this :

    <toast launch="{&quot;type&quot;:&quot;toast&quot;:&quot;param1&quot;:&quot;12345&quot;:&quot;param2&quot;:&quot;67890&quot;}">                        
        <visual>
            <binding template="ToastImageAndText01">
                <image id="1" src="ms-appx:///images/redWide.png" alt="red graphic"/>
                <text id="1">Hello World!</text>
            </binding>
        </visual>
    </toast>
    I took the above XML snippet from http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868212.aspx

    If your toast XML does not the "launch" attribute defined, then the "OnLaunched" method may not execute. I can see that you're using Mobile Services to implement Push Notifications,  this  article should be helpful.

    Sagar

    Monday, May 12, 2014 2:29 PM

All replies

  • Hi,

    Could you please provide more information about the problem? Are you facing issues while receiving the Push/Toast notifications? Or experiencing problems while navigating to the Page after the Toast notification is tapped?

    Sagar

    Friday, May 09, 2014 3:27 PM
  • Thanks sagar. Let me explain this better.

    So the app receives an Push/Toast notification. When user click on that notification ,the application should launch a page(bluesetinstruction).

    It used to do that earlier but not anymore. When i click on notification ,nothing happens.


    • Edited by Raj12_T Friday, May 09, 2014 3:35 PM
    Friday, May 09, 2014 3:34 PM
  • Hi,

    Is the App already running when the Toast arrives? If yes, then you probably might have to change the code. I think you should check out the "App.xaml.cs" in the Toasts sample and Scenario #4 . My guess there is a possible issue with how activation-from-toast is handled.

    Sagar

    Friday, May 09, 2014 5:43 PM
  • Yes the app us running when push notification is shown. I have put a breakpoint on launch string .But when push notification is clicked ,the launch string is never called. Why is that?
    Monday, May 12, 2014 1:10 AM
  • Hi,

    The toast notification that you send needs to have the "launch" attribute defined and the toast template would look something like this :

    <toast launch="{&quot;type&quot;:&quot;toast&quot;:&quot;param1&quot;:&quot;12345&quot;:&quot;param2&quot;:&quot;67890&quot;}">                        
        <visual>
            <binding template="ToastImageAndText01">
                <image id="1" src="ms-appx:///images/redWide.png" alt="red graphic"/>
                <text id="1">Hello World!</text>
            </binding>
        </visual>
    </toast>
    I took the above XML snippet from http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868212.aspx

    If your toast XML does not the "launch" attribute defined, then the "OnLaunched" method may not execute. I can see that you're using Mobile Services to implement Push Notifications,  this  article should be helpful.

    Sagar

    Monday, May 12, 2014 2:29 PM