WP8.1 silverlight - Notification activated event not being called - windows-phone-8.1

I am working on a Windows Phone 8.1 silverlight app, raw notifications handling.
The App when receives notifications in foreground, has to cancel the notification and create a new notification using ToastNotificationManager.CreateToastNotifier().
It also has a backgroundtask to work on the raw notifications received in background, which converts the raw notifications received to toast notification using ToastNotificationManager.CreateToastNotifier().
Also some action A needs to be performed on clicking of this notification.
The issue arises when the App receives the notification when in foreground, but the notification is clicked after suspending the application. Since the registered activated event of such type of notification is not in the background task (because the notification was formed in the foreground logic), no action A is performed on clicking of the notification.
This seems to a limitation, for WP8.1 silverlight apps. Can somebody suggest a solution for this issue??

If you need to do some action after tap on Toast you should add wp:Param to your Toast with deep url and handle in you app.
Toast will be look like
<wp:Notification xmlns:wp=\"WPNotification\">
<wp:Toast>
<wp:Text1>You title</wp:Text1>
<wp:Text2>Your subtitle</wp:Text2>" +
<!-- You can add any parameter you want in deep url -->
<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>
</wp:Toast>
</wp:Notification>
When you tap on toast it by default will open Page2.xaml of your app and pass uri parameters to it

Related

XCUITest - How to access the app device token in XCUITest for triggering the push notification but without setting any UIView in app code?

Objective:
I want to retrieve the app device token for triggering a push notification in XCUITest. To perform the following tests
Tapping on the push notification
Asserting the push notification texts
Taking a screenshot of app's main screen once the push notification is received.
Limitation:
I should not create any UIView in the app code for retrieving the device token in my XCUITest.
Please suggest me if there is any other workaround considering the limitation.
Answered here (same asker, I assume): https://forums.developer.apple.com/thread/110361

There is a way to send custom data in push notification in Windows Phone?

I know that are Raw Notifications on WNS but the whole content of the notification is showed in the notification. I wanted to do like APNS and GCM does. A custom properties in the json payload that it's delivered to the app but its not showed to the user. There is a way to do that in WNS?
You can send parameters in launch attribute, it can be similar to url. For example, for toast notifications:
<toast launch="?param1=sample&param2=sample2">
</toast>
and parse it in the application. Value from launch attribute can be retrieved in OnLaunched handler. HERE is an article about handling activation from a toast notification (from MSDN).
Note: you can put into launch any other format you want. I suggested uri-based parameter because it is easy to parse using WwwFormUrlDecoder, which is mentioned HERE.

How to trigger a "flyout, dialog, app bar or other inline element" if the phone receives a notification while the app is closed?

I'm working on a Windows Phone app that will receive push notifications and needs to show critical alerts to the user. As far as I can see there are 3 types of push notification:
Raw Notification - Raw notifications are used when your application is actually running on the device. This allows you to
update your interface “live” as the user is using it.
Toast Notification – This message will be received regardless of whether your application is running or not, but popping toast messages
while your app is running might be a little annoying. I’ll
demonstrate this example below. Toast WILL NOT also update your
application’s data. You still need to pass a Raw Notification to make
this happen.
Tile Notification – If your application is pinned to the user’s Start screen, you can update the Tile for your application. You can
change the background image, as well as an integer from 0-99.
source: http://www.jeffblankenburg.com/2010/10/19/31-days-of-windows-phone-day-19-push-notifications/
These each have different behaviours, but none lend themselves to critical notifications, where the user can be actively alerted to critical information.
Having read Guidelines for toast notifications on MSDN, it suggests
Don't use toast notifications to notify the user of something that
must be seen, such as a critical alert. To ensure that the user has
seen your message, notify them in the context of your app with a
Flyout, dialog, app bar, or other inline element.
So the question is, how can I trigger a "flyout, dialog, app bar or other inline element" if my app is closed and the phone receives a critical notification.
long story short: you can't enforce that your app opens on an incoming pns
But I think you've got the toast scenario wrong. A toast can be used to notify the user, if he taps it the app opens and you might react to that by the navigation uri (e.g.: ?fromToast=true).
If you receive a toast notification while your app is open the toast won't show. Toast Notifications only get displayed when your app isn't open. But you can react to an incoming toast notification (there's an event for that) to implement an behavior of your way (e.g.: flyout, msgbox, ...).
note: introduced with GDR3: The sound of the toast notification can now be changed (even made silent).

wp8:Handle Toast notification when application is in backgroung

While my app is running I can receive toast notification,on ShellToastNotificationReceived(object sender, NotificationEventArgs e) event handler as keys in e.Collection.
If my app is not running and a toast notification arrives, a toast is displayed but how i can i handle this notification?
I mean which event is fire when my application is not running and notification arrives.
I know background agent but its not fulfill my requirement
Thanks.
Windows Phone platform is responsible to handle Push Notifications and developers don't have a direct access for notification handling when an app is not running. That means you can't do any background logic after Toast is received. But when Toast message contains <wp:Param> value with an Uri to a specific app page then user will be redirected to this page, if user taps a Toast popup. So, you can do specific job after user tapped a Toast popup. To accomplish it, you need add an parameter to Uri, for example /YourPage?IsToast=true and override OnNavigatedTo method of the page to run your business logic:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.ContainsKey("IsToast"))
{
//do your business here
}
}
For other cases you need to use a background worker.
yes we can handle the toast notification. once the user clicks on toast notification we can send a request to our web service and do our job.
what happens when an user clicks on toast notification is it will redirect to the application launching event in App.Xaml.cs page. in that event depending upon the toast content you can proceed to the next step.
hope this helps.
still if you didn't get it done, just drop a mail to me
happy coding.

Handle push notification on background

I am developing an application in windows phone which having push notification facility. I am able to receive push message at device.
If Application is not running , I am getting message at home screen on the click of that msg it starts that application. I want to perform some task on the basis of that Push Notification Message. But i am not able to handle that event.
Please help me to handle that EVENT if application is running or application is in background or application is not running .
Thanking You,
Which type of notification are you sending? Based on your question I assume you are referring to toast notifications.
When do you want to perform the task - before or after the user clicks on the message? If the application is not running, you can only do it after clicking the message.