PushNotificationReceived event doesn't fire - c#

I am developing Windows Phone 8.1 app and I have this issue.
I don't want my push notifications to pop when the app is in foreground - so when the notification received from PushNotificationChannel I am checking if the app is in the foreground on PushNotificationReceived event, if so, I am canceling the notification by:
args.
void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
{
if(appInForeground)
{
args.Cancel = true;
}
}
My PushNotification background task (IBackgroundTask) trigger is PushNotificationTrigger.
The issue:
Sometimes when the app is in foreground - I am receiving push notifications. When I look into logs I can see that PushNotificationReceived event didn't fire.
I am not unsubscribing form the event in my whole app life...
Can it be possible that the event didn't fire but my backgroundTask trigger did?
Something is fishy here...
Any help will be appreciated.

There is an option in the push notificaton system of windows to suppress popup when the app is in foreground. So basically the xml for the push notification should have this property defined when sending a push to device.
As of Windows Phone 8.1, the phone can also keep a toast notification from being displayed through use of the ToastNotification.suppressPopup or ScheduledToastNotification.suppressPopup property in the notification's XML content.
More details present in this link here . Hope this helps!

Related

Trigger suspension events in a Windows Store app App 8.1

How to trigger suspension of events in a Windows Store app App 8.1 after being idle for a certain period of time? Or simply how to suspend it after being idle for a certain period of time?
You can't force suspend the app, you can terminate it, it'll be suspended automatically after a period of time.. but you can trigger that by subscribing to OnSusbended Event in app.xaml.cs:
this.Suspending += OnSuspending;
Handler:
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//Use deferral for await calls :)
deferral.Complete();
}
Btw, you can debug it using VS, refer to this:
https://msdn.microsoft.com/en-us/library/hh974425.aspx
UPDATE:
Because the app is Suspended, you can't run a code to check, but what you can do is: Save a value to the settings in your app once the app is suspended, let's say it's: IsSuspended = 1, and make it 0 whenever the app rises OnActivated Event, this is a good way to check from a BackgroundTask or your foreground app after resuming.

How many WinForm event message are in queue?

I have created an event in a BackgroundWorker to send text notifications to a WinForm Panel. After the BachgroundWorker is finished I change the Panel and start the next BackgroundWorker.
My Problem is that when the BGW is finished not all event messages are arrived in my Panel.
Bevor removing the Panel I want to process all event messages.
How can I observe or check if there are more event messages in queue?
thanks for your help
PeekMessage is your friend. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms644943(v=vs.85).aspx for description

Minimize Event ( C# Win 8.1 app)

I'm developing an App for windows 8.1 and i need to execute a method to pause some tasks or play a sound when the app is minimized in the sidebar.
I tried:
Application.Current.Suspending += new SuspendingEventHandler(Method_Name);
private void Method_Name(object sender, object e)
{
Other_Method();
}
But this event takes a few seconds (5~10) to occur after I minimize the app.
What event occurs when the app is dragged to the sidebar? What process sends the event?
Thanks.
Check out this post for the answer. It's WindowSizeChanged and check the value of ApplicationView.Value.
[EDIT]
Apparently for 8.1 things have changed a bit. The ApplicationView stuff is deprecated (that was quick) but this still takes place in SizeChanged for the window. Check out this for more details.
After long searching I found something that is not exactly what i wanted, but it works.
This event occurs everytime that visibility of the page changes (Is started, is maximized or minimized for exemple), then you must do some conditions using the if operator.
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(One_Method);
private void One_Method(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
if(Some_Condition)
{
//TODO: Code that you want execute.
}
}
I'll keep the answer in open for the case of someone knows something more efficient.

Detect restart in Windows 8 - SessionEnding not called

When the user shuts downs Windows 8 from the Settings charm, my WPF application can detect that with the SessionEnding event.
In the case of choosing Shut down, I get "Session Ending Due To SystemShutdown"
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
private void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
Trace.WriteLine("Session Ending Due To " + e.Reason);
}
Shut down calls SessionEnding, but Restart does not
But when the user chooses Restart then SessionEnding is not called!
Detecting Restart intent in Windows 8
How can it be done?
Here they say that by watching for WM_EndSession message you should be able to watch for a reboot: http://www.autoitscript.com/forum/topic/94616-detect-windows-shutdownlogoffrestart-event/
You will also need to hook to WndProc in your WPF application : How to handle WndProc messages in WPF?

Is there an event listener for the Devices charms button click?

I'm developing a windows 8 metro app and want to know if there is any way to listen for the devices charms bar button being selected? I'm trying to come up with a good way to create print page data without having to do it every time content is changed on my page.
I am setting up the share contract event listener right now and noticed there is a DataRequested event that fires when you click the share charms button.
DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;
Is there something similar I can implement for the Devices charms bar button click?
Check out http://www.jeffblankenburg.com/2012/11/20/31-days-of-windows-8-day-20-printing/ for a printing code sample in C#. You will need code like this:
PrintManager manager = PrintManager.GetForCurrentView();
manager.PrintTaskRequested += manager_PrintTaskRequested;
And of course, an implementation of the "manager_PrintTaskRequested" event handler. See the article for complete details.

Categories

Resources