I have a requirement where I have to detect if the user is not doing on Application and Application is idle(for certain period of time) and in the meantime, i.e while the application is idle before device screen gets locked, I have to show some images one by one.
I have gone through MSDN documentation of PhoneApplicationService.UserIdleDetectionMode and PhoneApplicationService.ApplicationIdleDetectionMode but i didn't found anything helpful.
How can i detect that application is idle ?
Thanks in advance.
Detect that the application is NOT idle: Create a class containing a timer. When the timer fires, show the images. Whenever the user does ANYTHING on ANY page (detect this by e.g. overriding the manipulationstarted events), reset the timer to 0.
Related
I'm trying to code a Timer-App with C# for Windows Phone 8.1 Runtime. My goal is to show a dialog and play a sound file when the timer is ended. If the user press "OK" the sound is stopped. Also a "Snooze" function would be great. Maybe not in this app, but I'm planning a personalized alarm clock too. Because I could add the TimeSpan for the timer to DateTime.Now it would be the easiest way to trigger at a specified time. Here are some ideas i had, but they don't do exactly what I want.
Register a background task. But there's no trigger for a specified
time. Only a TimeTrigger which fires at most every 30 min. A
solution, not very resource friendly, methinks, would be to look up
if the expected time is within the next 30 minutes and await the specified
time in the background task and use a ContantDialog. Not sure if this is possible at all.
Another possibility is to use a toast notification, but there is no
possibility of interaction and it is not very impressive, if you want
someone to notice the timer.
Alarms and Reminders are no longer available for RT apps...
Is there no other way? If there is a trigger for background tasks if internet connection is active, isn't there any trigger for a scheduled time? Or maybe a possibility to code something like the old Alarms and Reminders by myself?
Sorry that there is no code. But I don't have some useful code for this problem yet.
How would you solve this problem? Maybe for a timer, an alarm clock, a calender, a task reminder or something else that needs an interaction at a scheduled time. Thanks for your help.
The only real way to achieve this is with an Alarm, which (as you note) is Silverlight only.
For a runtime app a toast is closest, but isn't as alarmy. Once the user taps the toast (if at all) then it can launch the app for more detail. Toasts (especially when linked to a tile update) are good for calendar and task reminders, but if you want an alarm you really need the (Silverlight-only) Alarm API.
A Background Task cannot show any UI (other than raising a toast, which doesn't need the background task), so even if you could get the timing right it couldn't show the ContentDialog.
Current scenario stands like this:
User opens my app
Background audio agent starts playing
User goes back to start screen
Audio keeps playing from the background audio agent
User kills the application from the "task bar" (the closing button in upper right corner)
Background audio agent keeps playing.
I need to achieve following:
Close the audio background agent when the user kills the application (I know that I can use the close method on the backgroundaudioplayer but I need to call this when the application is killed/exited).
Questions:
Is there any event besides: Application_Deactivated / Application_Closing when the user truly exits/kills the application?
If there is no event like mentioned above - can I tell from Application_Deactivated / Application_Closing when the user really exits/kills the application?
Thank you
there is no way to detect when an app got closed by the task switcher or system. Usually apps keep tombstoned until they get either reactivated or killed. You have to do all the clean-up work in the Application_Closing and Application_Deactivated events.
This has one simple reason: When an application lies in the background it is freezed and cannot execute code. Whenever the user or the system kills it (to get more memory for example) the app and all its data get completely wiped out of the memory. Without notifying your app and without giving it the chance to gain performance (which would be counterproductive).
So you just have the chance to use the Application_Deactivated event when the user tap the start button or another app is launched or the Application_Closing event when the user closes the app via back button.
Read this if you need additional information about the Windows Phone 8 Application lifecycle.
Beside this a user would expect that the background audio is still running after he closes the application. A podcast for example should also play when I closed the podcast app. What kind of audio are you talking about? Maybe we can find a smart solution...
The only events you can react to are Closing and Deactivated.
So here,you can call BackgroundAudioPlayer.Instance.Close() in "Application_Closing" event only.
I am trying to detect the Idle time in a Windows Mobile application and show a Screen lock after this inactive period. This link http://blog.opennetcf.com/ctacke/2009/05/19/DetectingApplicationIdle.aspx gives a hint but I found that this works only for a single form.
How can this same code be used across an application with multiple forms. I tried implementing this code after the InitializeComponent() for each form and used the Reset() function in the form Activate and GotFocus event so that the timer is reset after the user closes the screen lock by entering a PIN number. But this does not seem to work for multiple forms and the timer is not reset but it keeps firing every minute. Even if I am working on the application the event fires up every 1 minute (as per the sample code) and this is not correct.
Can anyone suggest how to use this functionality across the entire application.
Thanks in advance for any solution.
We need to see your code to know what's wrong, but the method proposed in that blog entry uses an IMessageFilter implementation. That hooks into the Windows message pump, which is application-wide not a single-Form system. I use the exact same technique for application-wide idle detection in a couple of solutions and it works well.
My guess is that you have a scope issue with the IMessageFilter instance you're using. If you create it as a Form-level variable (like the sample in that blog does), when close the Form that the filter is disposed of and will no longer work. If you have multiple Forms, you need to put it somewhere else in the Model so it survives as long as the app is up.
What about utilizing GetIdleTime ? Seems like this, paired with a timer that wakes peroidically to check it, could detect system idle and allow you to show the screen lock.
Windows resets the IDLE time every time the user touches the keyboard or the mouse. My application needs to reset the IDLE time at specific moments, but i can't figure out how to do this programmatically.
The following does NOT reset the IDLE time using VB, C# or QT4.
- Programmatic mouse movement / click.
- Programmatic keystroke.
Somehow Windows knows these actions are simulated.
How can i reset the IDLE time? Any thoughts will be greatly appreciated!
Use SetThreadExecutionState(). The ES_SYSTEM_REQUIRED option (2) resets the system idle timer. Visit pinvoke.net for the required declarations.
If you need the display to stay on for example, you would call SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);
On 2000/XP you could use the ES_USER_PRESENT flag (Does not work on Vista+)
To disable the screen saver, you can handle WM_SYSCOMMAND's SC_SCREENSAVE (You must be the foreground window, otherwise use SystemParametersInfo)
In principle SetThreadExecutionState() should do what you need. But I have found it not to work with the system required flag in some situations on some modern Windows. Sorry, I can't remember exact details.
As a fallback you can just fake some input by calling SendInput() with a null mouse move message for example. My guess is that your input faking failed because you called SendMessage or PostMessage.
I have an game application I have written for Windows Mobile and I want to have a timer associated with the puzzle. If the program loses focus for any reason (call comes in, user switches programs, user hits the Windows button) then I want a pop up dialog box to cover the puzzle and the timer to stop. When the user closes the pop up dialog the timer can start up again.
Does anyone know how to do this?
Thanks
Take a look at the article over at OpenNETCF's Community site on determining when a Form or Process changes.
A quick way would be to use PInvoke to call GetForegroundWindow() and GetWindowText() whenever your timer ticks (once a second?).
GetForegroundWindow() returns a windows handle which you can use to call GetWindowText(). If the text of the foreground window matches your form's Text property (its caption), you know your app has the focus. You can then show or hide your puzzle in each timer tick.