How to schedule notification to user on specified time - windows-phone-7

In my app I need to schedule notification to user on specified date and time (for example 1st May at 10:00). At this moment notification must be shown and when user clicks on this notification, my app should be open. I see two ways to do it:
1. Scheduled notifications. But if I use the Alarm class, I can not change the title of the notification (which is "Alarm" in English version of SDK).
Reminder class mostly suits me, but when it appears atop the lock screen and user clicks it, my app doesn't open. May be is there a way around these moments? Also I would like to get rid of listpicker with time (5 min, 10 min, 1 hour, etc.) and the "snooze" button, but it's not critical.
2. Toast (or tile) notifications from background agent. But I'm not sure that my background agent runs at the right time. As I understand the background agents runs by the system, and their launch is limited by several factors (phone battery charge, the presence of the running applications or other background agents). It may not even start. There is a way to force the agent at a specific time by using the LaunchForTest, but everywhere write that this method can be used only for debugging purposes, and before the publication of the application it must be removed.
If I do not delete this method, will my application be certified? Also I don't like that the toast notification is only opens for 10 seconds and then disappears without a trace. Something can be done about it?
I need to notification was guaranteed shown at the right time, and when you click on it my application was open. What is the best way to do this?
If this is not possible in Windows Phone 7, is there a way to do this in Windows Phone 8?
Thanks.

I think you should use the Reminders for this. When you click them your application will open.
Something like:
var reminder = ScheduledActionService.Find("MyAppReminder");
if (reminder != null)
{
ScheduledActionService.Remove("MyAppReminder");
}
reminder = new Reminder("MyAppReminder")
{
Title = "Bla",
BeginTime = DateTime.Now.AddDays(2),
Content = message,
NavigationUri = new Uri("/Start.xaml", UriKind.Relative),
RecurrenceType = RecurrenceInterval.None
};
ScheduledActionService.Add(reminder);
As for the application not opening when the notification appears on the lock screen, it makes sense. Would be a big security hole if you could open apps directly from the lock screen! Hope it helps.

Related

Getting notified of any action taken by user on windows

I am laying out a concept for an app and in it,i need the administrator to get notified of any action a user takes like starting a program,opening a folder,renaming a file,deleting files,opening files etc.
The concept i am thinking of is like jquery events
$('.class_here').click(function(){
alert('some one clicked the start button');
});
but this is on windows.I have looked at the documentation for windows event viewer and event logs but i would like more direction if this sort of thing is available on windows.
Thanks.

Adding alarm from BackgroundAgent (not working, looking for workarounds) - Windows Phone 8

I am developing an application which needs to notify the user at a pre-difined time with the help of background agent,
So I tried to add an Alarm, but according to MSDN's "Unsupported APIs for Background Agents for Windows Phone" all the methods regarding Microsoft.Phone.Scheduler (Add, Remove, Replace) are not supported (when ever i try to call Add method from background agent it gives error "BNS Error: The API can only be called from foreground app".). I tried to add the alarm when in foreground and then play with the "BeginTime" property and use the Replace method from the my scheduledTask (specifically, PeriodicTask which runs its code every 30 minutes) but to no avail, it did nothing.
What is important for me is to notify the user (with longer-enough sound) at the date and time that decided in the background-agent's Invoke method (My class derives from ScheduledTaskAgent and override the Invoke method), So I'm looking for workarounds. If there would be a toast that appears at a pre-defined time that would be ok somehow. Or maybe a toast that stays for a longer time on the top of the screen (from the moment the scheduled-task came up with an instance of DateTime until[and even after] the time that specifiend in this DateTime instance).
Please confirm, is it only the background agent that can calculate the correct time for the alarm to go off?
Assuming this is so, you can notify the user by sending a toast (which will also vibrate the phone, unless user has disabled that) and updating a tile pinned to the home page. These are both permitted APIs. So the toast message could tell the user to go look at the tile, which could have specific details about the alarm. The tile state will persist until you change it. If your foreground app would pin the tile for the user, that's a start. If you can then get the user to move the tile to the top of the screen, so it's always visible, you should be all set.
Considering that the alarm time might happen when the user is not actively using the phone, perhaps you want to do the toast plus a notification on the lock screen (as well as updating the tile)? That will provide another visual indication, though, again, it depends on the user configuring a lock screen.

Async cancellabel task

I want to implement a behaviour for my application that at the start checks a webservivce if any news are available. If there are news available, pop open a screen to show to the user. If there are no news available, or the user quits the application (or starts the game) i dont want to bother the user but instead cancel the task to retrieve the news item
I thought it would be a breeze doing this with the Task Library but unfortunatly it is not available in the default loadout on Windows Phone (or is it?).
I think the key here is the cancelable part. I certainly know how to start an async op, but what is the best practice for hte cancelable part?
The Task Parallel Library is available for Windows Phone, in this NuGet package: System.Threading.Tasks.
But I don't really get why you care to cancel the task. If the user quits the application, the task end, and if you do another action, nothing happens.

netServiceBrowserDidStopSearch not called

I'm now writing a Bonjour service listener class, according to the document here:
Currently, it seems working, I can receive "netServiceBrowserWillSearch:" and "didFindService:moreComing:" correctly. However, after a long wait, I cannot receive " netServiceBrowserDidStopSearch:" or "netServiceBrowser:didNotSearch:". Therefore I don't know that is the proper time for my delegate class to stop showing some UI.
Could anyone have an idea for this? Thanks.
NSNetServiceBrowser doesn't stop browsing (and call the -netServiceBrowserDidStopSearch: delegate method) until you explicitly tell it to by calling -stop. After it's found the initial services, it continues informing you as new matching services are added or old ones disappear.
How you handle this depends on how you want your app to behave. If you have a window that continuously shows the available services (e.g. like the Bonjour window in iChat), then it's best to let it continue, and contiuously update the list in response to delegate messages. If you've got more like a dialog that gets populated and then goes away once the user makes a selection (e.g like the system Add Printer... dialog), then you want to keep the browser running while it's displayed, then call -stop once the user dismisses it. If you're waiting to find just one specific service, then you can call -stop once you've found and resolved it.

Session 0 Isolation

Vista puts out a new security preventing Session 0 from accessing hardware like the video card, and the user no longer logs into session 0. I know this means that I cannot show the user a GUI, however, does that also mean I can't show one at all? The way my code is set up right now, it would be more work to make it command line only, however if I can use my existing code and just programmatically manage the GUI it would take a lot less code.
Is this possible?
The article from MSDN says this:
• A service attempts to create a user interface (UI), such as a dialog box, in Session 0. Because the user is not running in Session 0, he or she never sees the UI and therefore cannot provide the input that the service is looking for. The service appears to stop functioning because it is waiting for a user response that does not occur.
Which makes me think it is possible to have an automated UI, but someone told me that you couldn't use SendKeys with a service because it was disabled in Session 0.
EDIT: I don't actually need to show the user the GUI
You can show one; it just doesn't show up.
There is a little notification in the taskbar about there being a GUI window and a way to switch to it.
Anyway, there actually is a TerminalServices API command to switch active session that you could call if you really needed it to show up.
You can write a separate process which provides the UI for your service process. The communication between your UI and service process can be done in various ways (search the web for "inter process communication" or "IPC").
Your service can have a GUI. It's simply that no human will ever see it. As the MSDN quote suggests, a service can display a dialog box. The call to MessageBox won't fail; it just won't ever return — there won't be anyone to press its buttons.
I'm not sure what you mean by wanting to "manage the GUI." Do you actually mean pretending to send input to the controls, as with SendInput? I see no reason that it wouldn't be possible; you'd be injecting input into your own program's queue, after all, and SendInput's Vista-specific warnings don't say anything about that. But I think you'd be making things much more complicated than they need to be. Revisit the idea to alter your program to have no UI at all. (That's not the same as having a console program. Consoles are UI.)
Instead of simulating the mouse messages necessary to click a button, for instance, eliminate the middle-man and simply call directly the function that the button-click event would have called.

Resources