Handling toast notification in Windows Phone 8.1 when app is closed
Asked Answered
E

1

9

I'm handling Toast Notifications on Windows Phone 8.1 app (using HTML/JS,CSS) when user click on notifications(On action bar) with the following code snippet: Reference: https://msdn.microsoft.com/en-us/library/windows/apps/hh761468.aspx

WinJS.Application.addEventListener("activated", onActivatedHandler, false);

function onActivatedHandler(args) {

    if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
        localStorage.messageDetails = args.detail.arguments;
        window.location.href = "index.html";
    }
}

It works well when the app is running in foreground or background. But, when I click on notifications, it is not hitting the above code snippet when the app is not running (foreground or background). I don't know what I'm doing wrong. Please help me on this. Thanks in advance.

Endocrinology answered 7/8, 2015 at 11:49 Comment(0)
S
1

I do not know technical reason why it is not working as you have implemented it right way. But there are two points I want you to check and I hope your issue will be solved.

  1. Try using pushnotificationreceived event, it will give you whole toast notification xml string and you can further work on it.

  2. It is possible that the page is not able to load the whole html and javascript when a launch is triggered. So you can use Window.SetTimeout for 1 second or more seconds delay inside the If condition of activated event handler.

Scepter answered 17/8, 2015 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.